Author Topic: Using three template files at a time  (Read 2575 times)

0 Members and 1 Guest are viewing this topic.

Offline IGC

  • Newbie
  • *
  • Posts: 29
  • http://www.theanimegallery.com
    • View Profile
    • theAnimeGallery.com
Using three template files at a time
« on: May 11, 2007, 07:42:10 PM »
Hello...

I am trying to use this code:

Code: [Select]
$site_template->register_vars(array(
"news_id" => $news_id,
"news_time" => substr($news_row['news_date'], 11),
"news_date" => substr($news_row['news_date'], 0, 10),
"comments_count" => isset($comment_count['count']) ? intval($comment_count['count']) : 0,
"news_views" => ($user_info['user_level'] != ADMIN) ? $news_row['news_views']+1 : $news_row['news_views'],
"news_title" => $news_row['news_title'],
"author_name" => "<a href=\"member.php?action=showprofile&amp;user_id=".$news_row['user_id']."\">".$author['user_name']."</a>",
"author_avatar" => $author['user_avatar'],
"news_text" => $bb->parse($news_row['news_text'])
));
$content = $site_template->parse_template("news_show");

$leave_comment_box = "test";
if($user_info['user_level'] > GUEST){
//Can leave comments
$leave_comment_box = $site_template->parse_template("news_comment_box");
}
else{
//Guests cannot leave comments on news
$leave_comment_box = 'Only registered users can post comments<br /><a href="register.php">Register here</a>';
}

$site_template->register_vars(array(
"comment_box" => $leave_comment_box));

As you can see, I call $site_template->parse_template() twice in that section.

The main template is the place holder for all news-type pages.
Inside that page, the content changes depending on the action being performed: (view all news, view a single news, post a comment, edit a comment...)

The third template comes into play when a user is viewing a single news and the user is a registered member of the site.
In this case, I want to show a COMMENT BOX where they can leave a comment, if the user is not registered a little message appears saying they need to register to leave comments...

If I add my comment box html code using a string $comment_box = "<table .......................</table>" everything is fine, but I wanted to save that in a template so it is easier to modify.

The portion that is failing is the second call to parse_template... it is being called but it is returning an empty string... when it should be parsing a file I have created...

The third called to parse_template is at the end of the file: $site_template->print_template($site_template->parse_template($main_template)); and it is the normal call to print the file.

The file is correctly created, it exists and is placed inside the template directory.

Any suggestions??

Thanks

Offline IGC

  • Newbie
  • *
  • Posts: 29
  • http://www.theanimegallery.com
    • View Profile
    • theAnimeGallery.com
Re: Using three template files at a time
« Reply #1 on: May 11, 2007, 08:00:10 PM »
I've solved the problem for this particular case using {if xxx} and {ifnot xxx}, but I would like to know if it is possible to invoke parse_template more than once.... because it seems like once you call parse_template everything else does not work....

However, the thumbnail_bit is called everywhere and does not affect the rest of the code... so I would like to know why.