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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.