work_it_work Posted November 27, 2012 Share Posted November 27, 2012 i got a php website based on templates, and i want to make some changes. it's based in header.tpl; mainpage.tpl; and footer.tpl what i want to achieve is to have 2 header.tpl pages displayed separately. or at least 2 different headers. on index.page i want to display header1.tpl and on any other page i want to display header2.tpl how can i do that? please help! Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/ Share on other sites More sharing options...
Beeeeney Posted November 27, 2012 Share Posted November 27, 2012 Post your code and go into detail with the problem you're having. You'll get better help. Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395460 Share on other sites More sharing options...
work_it_work Posted November 27, 2012 Author Share Posted November 27, 2012 Here's the code that triggers the template: $template_output .= $template->process('header.tpl.php'); what i want to do is to process the header.tpl.php only if the current page is index.php on any other page i want to process the header2.tpl.php so visitors when enter the www.site.com or www.site.com/index.php will see one version of the header, and if the navigate away from index.php page they will see another header on the page basically the difference between the 2 header.tpl.php files is one jquery banner.... Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395468 Share on other sites More sharing options...
NomadicJosh Posted November 27, 2012 Share Posted November 27, 2012 Without know the rest of the code surrounding the template output, it would be difficult to give a clear solution, however, maybe this will give you some ideas: function header( $name = null ) { if( isset($name) ) $template_output .= $template->process('header-{$name}.php'); $template_output .= $template->process('header.php'); } Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395512 Share on other sites More sharing options...
work_it_work Posted November 27, 2012 Author Share Posted November 27, 2012 (edited) i need something simple, exactly like this: if the current page is www.site.com/index.php process header.tpl.php if the current page is not www.site.com/index.php process header2.tpl.php please help Edited November 27, 2012 by work_it_work Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395629 Share on other sites More sharing options...
cyberRobot Posted November 27, 2012 Share Posted November 27, 2012 You could try something like the following: $templateFile = ($_SERVER['PHP_SELF'] == '/index.php') ? 'header.tpl.php' : 'header2.tpl.php'; Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395638 Share on other sites More sharing options...
work_it_work Posted November 27, 2012 Author Share Posted November 27, 2012 but if the visitor just came in and the address is only www.site.com ? does it work? Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395644 Share on other sites More sharing options...
cyberRobot Posted November 27, 2012 Share Posted November 27, 2012 As long as your website is set so that visits to "www.site.com" show the index.php file, the code provided should work. Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395647 Share on other sites More sharing options...
work_it_work Posted November 27, 2012 Author Share Posted November 27, 2012 (edited) great, and how would i integrate that function to my function: $template_output .= $template->process('header.tpl.php'); thank you! Edited November 27, 2012 by work_it_work Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395652 Share on other sites More sharing options...
cyberRobot Posted November 27, 2012 Share Posted November 27, 2012 That kind of depends on your code. You should be able to do something like: $templateFile = ($_SERVER['PHP_SELF'] == '/index.php') ? 'header.tpl.php' : 'header2.tpl.php'; $template_output .= $template->process($templateFile); Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395655 Share on other sites More sharing options...
work_it_work Posted November 27, 2012 Author Share Posted November 27, 2012 i've tried that but it only display the header2.tpl.php page. doesn't matter if is /index.php or /search.php ...any ideea? Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395659 Share on other sites More sharing options...
work_it_work Posted November 27, 2012 Author Share Posted November 27, 2012 well it works now, thank you very much!! it wasn;t working because it was a directory involved, now it works! Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395664 Share on other sites More sharing options...
cyberRobot Posted November 27, 2012 Share Posted November 27, 2012 well it works now, thank you very much!! it wasn;t working because it was a directory involved, now it works! I'm glad to hear that Quote Link to comment https://forums.phpfreaks.com/topic/271236-php-template-process-if-function-please-help/#findComment-1395669 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.