ShoeLace1291 Posted February 14, 2009 Share Posted February 14, 2009 I have a function that passes two variables, an array of variables and a file. The variables in the array are supposed to be passed from the PHP file to the TPL file so that there is no need for PHP code in the TPL file. I use this function multiple times in my index page but only works 2 out of the three times it's used. The first use is in the page header template. Next, is the index body template, which is the one that doesn't work. Last, is the footer template which works. This has me stumped because all the syntax looks the same. This is my index file: require('config.php'); include('sources/source_index.php'); $vars = array( 'PAGE_TITLE' => "Home" ); $file = "template/overall_header.tpl"; echo buildTemp($file, $vars); $vars = array( 'HEADING' => "Welcome!", 'BOARDNEWS' => ssi_boardNews(60), 'EPICBATTLES' => recentBattles(), 'COMMUNITY' => ssi_recentTopics($numrecent = 10), 'NEWCOMERS' => newmembers(), 'LIVESTATS' => ssi_boardStats(), 'LOGONLINE' => ssi_logOnline() ); $file = "template/index_body.tpl"; echo buildTemp($file, $vars); $vars = array( 'COPYRIGHT' => '© 2009 Fourth Core Films, Inc. All rights reserved.' ); $file = "template/overall_footer.tpl"; echo buildTemp($file, $vars); Index Body: <div id='structure'> <div class='smallcontent' style='clear: both;'> <h1>The Scoop</h1> <span style='margin: 10px;'>BOARDNEWS</span> </div> <div class='smallcontent'> <h1>Epic Battles</h1> EPICBATTLES </div> <div class='smallcontent' style='clear: both;'> <h1>New Comers</h1> NEWCOMERS </div> <div class='smallcontent'> <h1>Live Stats</h1> LIVESTATS<br />\ Users Online: LOGONLINE</div> <div class='smallcontent' style='clear: both;'> <h1>Community Buzz</h1> COMMUNITY </div> <div class='smallcontent'> <h1>Sponsors' Words</h1> <script type="text/javascript"><!-- google_ad_client = "pub-0228252753561891"; /* 160x90, created 1/25/09 */ google_ad_slot = "0326972930"; google_ad_width = 160; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script></div> </div> buildTemp function: function buildTemp($file, $vars){ ob_start(); $file = file_get_contents($file); foreach($vars as $php => $html){ $temp = str_replace($php, $html, $file); } echo $temp; $ret=ob_get_contents(); ob_end_clean(); return $ret; } Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/145162-template-variables/ Share on other sites More sharing options...
ShoeLace1291 Posted February 14, 2009 Author Share Posted February 14, 2009 bump Link to comment https://forums.phpfreaks.com/topic/145162-template-variables/#findComment-762352 Share on other sites More sharing options...
ShoeLace1291 Posted February 16, 2009 Author Share Posted February 16, 2009 bump Link to comment https://forums.phpfreaks.com/topic/145162-template-variables/#findComment-763085 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.