Jump to content

Php Template System


doddsey_65

Recommended Posts

The current system I am using has worked so far but it has its problems. Basically I have 2 files to display forum topics.

 

view_topics.php and topic_list_tpl.php

 

view_topics.php defines some variables like so

 

$template->topic_name = $row[$key]['topic_name']

 

then it renders the page like so

 

$template->render('topic_list_tpl.php');

 

then in topic_list_tpl.php i use this to print the name of the topic

 

<?php echo $this->topic_name; ?>

 

which works fine. But as you know a topic list needs a header. But the render function is within a foreach loop so it displays all of the topics from the query. This poses the problem of the header being looped,  which it shouldnt be. So in view_topics.php i use:

 

$template->topic_id = $row[$key]['topic_id'];
$template->first_topic_id = $row[0]['topic_id'];

 

then in topic_list_tpl.php i can use:

 

<?php if($this->topic_id == $this->first_topic_id) {
echo the header
}
else
{
echo the topics
}

 

but the problem comes when adding a footer bar at the bottom(for the new reply link and other topic options).

i can use something like

 

$amount_of_topics = count($row);
$template->last_topic_id = $row[$amount_of_topics-1]['topic_id']

 

and then check it like that but that wont work when using pagination as the last topic displayed isnt always going to be the last topic in the query.

So another option i have is to have the header and footer bars in seperate files and call them outside of the loop. But these files would only be 2 or 3 lines each. So is this the best option? or is there an easier way of doing things?

Link to comment
https://forums.phpfreaks.com/topic/230727-php-template-system/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.