doddsey_65 Posted March 15, 2011 Share Posted March 15, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/230727-php-template-system/ Share on other sites More sharing options...
AbraCadaver Posted March 15, 2011 Share Posted March 15, 2011 Maybe I don't understand, but why not echo the header before the loop and the footer after the loop? Quote Link to comment https://forums.phpfreaks.com/topic/230727-php-template-system/#findComment-1187879 Share on other sites More sharing options...
doddsey_65 Posted March 15, 2011 Author Share Posted March 15, 2011 good question, i forgot to mention that the header has the name of the forum within it, which is grabbed from the query Quote Link to comment https://forums.phpfreaks.com/topic/230727-php-template-system/#findComment-1187881 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.