Jump to content


Photo

Help (please)! - Need new variable in a .TPL file


  • Please log in to reply
4 replies to this topic

#1 toasty

toasty
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 09 October 2006 - 02:09 AM

I need a solution to what's bound to be a really simplistic problem.  I'm running a php/mysql script on my site and one of the functions it performs to display a news/text post and dynamically link it to a corresponding image file.  If you're thinking "webcomic" you're right on the money.  The news posts are formatted according to a .tpl file.

The script itself is Comikaze and I've tried contacting the creator, but I've not heard anything back for quite some time and after several attempts.

The thing I need help with is that I need to insert a link into that .tpl (news_print.tpl) file that will dynamically link from the news post to the corresponding image page.  I've discovered that simply inserting PHP into the news_print.tpl file does not work.  What I thought I'd do would be to define a new variable that I'd be able to use inside the news_print.tpl file.

Variables that already exist are {NES_AVATAR}, {NEWS_POST}, {NEWS_DATE}, {NEWS_POSTER}, and a few others.

The variable I need is already used by the script elsewhere as $comic_id; the comic rotation/navigation uses it to, well "navigate."  However how to turn it into something that news_print.tpl can use... that's what I'm not sure about.  I did some serious digging and I found this specific file that looks like it has to do with the news_print.tpl, and is called newsDO.class.php.  Inside the code on line #48 begins the following code:
function formatNewsPost($poster,$email,$avatar,$title,$post,$time,$nl2br) {
	$post = $this->nl2brNewsPost($post,$nl2br);
	if (!empty($avatar))
		$avatar = "<img src=\"$avatar\" alt=\"$poster\" border=\"0\" />";
	$replace['{NEWS_POSTER}'] = $poster;
	$replace['{NEWS_EMAIL}'] = $email;
	$replace['{NEWS_AVATAR}'] = $avatar;
	$replace['{NEWS_TITLE}'] = $title;
	$replace['{NEWS_POST}'] = $post;
	$replace['{NEWS_DATE}'] = $time;
		
	return $this->_common->getTemplate('news_print.tpl', $replace);
}
I thought that if I added $comic_id into the function call on the first line and the $replace['{COMIC_ID}'] = $comic_id; down with the rest that this would allow me to use {COMIC_ID} as a variable with the news_print.tpl file.  Unfortunately, all it does when I attempt to use it is spits out this error:
Warning: Missing argument 8 for formatnewspost() in /var/www/html/smcomikaze/includes/classes/newsDO.class.php on line 48
My website is essentially done, this is the last bit of code I need to wedge into it and *poof* off it goes.  Once I can get this to work it's keg time!

Thanks to anyone who's taken the time to read this over!

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 09 October 2006 - 02:46 AM

You have to add to the function call, and the function it's self!

// function

function formatNewsPost ( $poster, $email, $avatar, $title, $post, $time, $comic_id, $nl2br )
{
	$post = $this->nl2brNewsPost($post,$nl2br);

	if (!empty($avatar))
	{
		$avatar = "<img src=\"$avatar\" alt=\"$poster\" border=\"0\" />";
	}

	$replace['{NEWS_POSTER}'] = $poster;
	$replace['{NEWS_EMAIL}'] = $email;
	$replace['{NEWS_AVATAR}'] = $avatar;
	$replace['{NEWS_TITLE}'] = $title;
	$replace['{NEWS_POST}'] = $post;
	$replace['{NEWS_DATE}'] = $time;
	$replace['{COMIC_ID}'] = $comic_id;

	return $this->_common->getTemplate ( 'news_print.tpl', $replace );
}

Then in your function call, make sure make sure param_7 represents the variable value for $comic_id

// function call

formatNewsPost ( $poster, $email, $avatar, $title, $post, $time, /*param_7, this where you would add the extra variable */, $nl2br );

replace /*param_7, this where you would add the extra variable */, with your added $variable!

me!

#3 toasty

toasty
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 09 October 2006 - 03:26 AM

Hey Printf, thanks for the suggestion - though unfortunately I'm still getting the same error. 
Warning: Missing argument 8 for formatnewspost() in /var/www/html/smcomikaze/includes/classes/newsDO.class.php on line 48

What you suggested makes sense though, the variable inside the function call (which is the 7th) must also appear as the 7th variable in the code as well.  Though it seems like it's still had the same effect... phoey. 

Edit - Something I just now noticed is that dispite returning that error message on the webpage, the {COMIC_ID} is returning a value of "1"; however in this specific example it should be returning a value of "6" as that is the ID number of the corresponding post.

I was totally surprised to get a response to my post so soon; if you've any other ideas, I'm all ears (so to speak).  Thanks Printf, and anyone else who feels like dumping some thoughts my way.  ;D

Oh, and just incase anyone feels like spending the time on it, here are the actual newsDO.class.php and news_print.tpl files if you're feeling that benevolent to skim through them; thought I totally don't expect it.

[attachment deleted by admin]

#4 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 09 October 2006 - 03:40 PM

The class is now fine, but where are you calling the class function needs the extra param added to it! Like I showed you in my second / lower code example!


me!

#5 toasty

toasty
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 09 October 2006 - 05:59 PM

Yes!!!

PrintF, you were right on the money!  I had to search around a bit and I found two files that called that function; it took me about fifteen minutes of looking around and figuring out the correct variable.  Once I updated all the function calls it was nearly working; instead of returning any errors it was simply returning a ID value of null.  I looked around and some of the other code in one of the files where the function was being called and rolled the roulette on $comicID instead of $comic_id and it all fell into place perfectly.  Every post on every page points to the correct comic.

I'm so pumped, thanks again PrintF, my site's now a hair's width from being done and smokin'.

Woo Hoo!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users