scottybwoy Posted August 8, 2006 Share Posted August 8, 2006 Could someone walk me through how to bring a template into the php code being executed, I can't find how to do it. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/ Share on other sites More sharing options...
bltesar Posted August 8, 2006 Share Posted August 8, 2006 create your template in a file, say header.htmthen, in your php code where you want the template to appear, place the following line:require('header.php'); Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-71220 Share on other sites More sharing options...
scottybwoy Posted August 9, 2006 Author Share Posted August 9, 2006 Thanks, another question, does this :[code]<?phpheader("Location: $AUTHENTICATION_URL?url=$this->self_url")?>[/code]call the Authentication URL into the page that is open? Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-71670 Share on other sites More sharing options...
bltesar Posted August 9, 2006 Share Posted August 9, 2006 I am not at all familiar with this construct. Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-71702 Share on other sites More sharing options...
onlyican Posted August 9, 2006 Share Posted August 9, 2006 What I do is have my website in 3 parts shall we sayHeader and navBody / ContentFooterThe header and nav does not include the doctype, html headers, but I suppose you can. My wayheader/nav file contains the header and navigation of your website (page banner and side nav for example) all which shows in body tagsThe footer shows the footerthen content is like[code]<html><head><title>MyTitle</title><meta....</head><body><?phprequire_once("inc_header.php");?>This is the body of that page<?phprequire_once("inc_footer.php");?></body></html>[/code]//Edit, only changed <? to <?php Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-71709 Share on other sites More sharing options...
scottybwoy Posted August 9, 2006 Author Share Posted August 9, 2006 So do you open index.html in the browser or index.php? Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-71770 Share on other sites More sharing options...
onlyican Posted August 9, 2006 Share Posted August 9, 2006 the pages would have to be php as you are using php code (unless you have your mimes set up)but each page you make, use the same layout.This means if you want to change the header, add a link in the nav, or change your footer, you edit one file, and all pages are updated, as all the pages are reading the information from that one file Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-71801 Share on other sites More sharing options...
scottybwoy Posted August 9, 2006 Author Share Posted August 9, 2006 Is that the same as having seperate .html files and including <!-- Start and End Comment Blocks --> Where you want to insert your php code? I understand that. What I don't quite get is how the .php file knows when to insert itself into the .html template. Can anyone point me in the right direction. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-71852 Share on other sites More sharing options...
bltesar Posted August 9, 2006 Share Posted August 9, 2006 When a .php file contains <?PHP ?> tags, it knows to execute the code within at the location where it is placed. Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-71874 Share on other sites More sharing options...
onlyican Posted August 9, 2006 Share Posted August 9, 2006 PHP Is a server side languageWhen you script contains <? or <?php (several other types but just use these 2) that data is passed to a PHP server, to read and translate back to HTM Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-71878 Share on other sites More sharing options...
scottybwoy Posted August 10, 2006 Author Share Posted August 10, 2006 Yeah I understand this much, from what I have learned about templates so far, is to have seperate template.html files set up as such :[code]<html><head><title>MyTitle</title><meta....</head><body><!-- START MainBody -->This is the body of that page<!-- END MainBody --></body></html>[/code]Then to have your file.php to call the code within the template between the comment blocks, however I don't know how it does it?This way I can say :If userID = foo then display baaelse display foobaaAny Pointers? Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-72346 Share on other sites More sharing options...
bltesar Posted August 11, 2006 Share Posted August 11, 2006 it seems we're not speaking the same language?! ???what exactly do you mean by template? If you mean a page with basic structure that is shared among many pages, but with some places for page-specific data within, it'll be something like thistop of page shared by all pagesa bit of data unique to pagemiddle of page shared by all pagesmore data unique to pagebottom of page shared by all pageswhat you do actually, instead of creating one template page, is create separate template pages for the parts that are shared by all pages, e.g. top.htm, middle.htm, and bottom.htm. then each page in your site will be a .php page that looks something like this:[code]<?PHP include(top.htm); //code to generate output unique to this page include(middle.htm); //code to generate more output unique to this page include(bottom.htm);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-72832 Share on other sites More sharing options...
scottybwoy Posted August 11, 2006 Author Share Posted August 11, 2006 This Guy here [url=http://forums.invisionpower.com/lofiversion/index.php/t198295.html]bfarber[/url] knows what I was trying to explain.That way you would only need one file for the top, middle and bottom and call the parts at seperate intervals.In theory one can also have a main bit of template also included that for intance has buttons to view reports, but with them labled like so in the html template:[code]<html><head><title>MyTitle</title><meta....</head><body><!-- START Administrator --><a href='superReport.php'>superReport</a><!-- START Accounts --><a href='accountsReport.php'>accountsReport</a><!-- START Sales --><a href='salesReport.php'>salesReport</a><!-- END Sales --><!-- END Accounts --><!-- END Administrator --></body></html>[/code]Now in your php file have this :[code]<?phpfunction whoReport()if {userType => 3 // 3 = Administrator$this->ipsclass->template['_wrapper'] = str_replace( "<!-- START Administrator -->" , $this->ipsclass->compiled_templates['skin_global']->adminReport(), $this->ipsclass->template['_wrapper']);} else if {userType => 2 // 2 = Accounts$this->ipsclass->template['_wrapper'] = str_replace( "<!-- START Accounts -->" , $this->ipsclass->compiled_templates['skin_global']->accountsReport(), $this->ipsclass->template['_wrapper']);} else {userType => 1 // 1 = Sales$this->ipsclass->template['_wrapper'] = str_replace( "<!-- START Sales -->" , $this->ipsclass->compiled_templates['skin_global']->salesReport(), $this->ipsclass->template['_wrapper']);}?>[/code]Along those lines, please note that code won't work. But you can see what I am trying to do now I hope. But if someone does know how to do this properly can they help me out, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-73010 Share on other sites More sharing options...
scottybwoy Posted August 14, 2006 Author Share Posted August 14, 2006 Also can you heve one template that is the main template that will always be there and have different templates fill the middle bit, or must you use frames? Quote Link to comment https://forums.phpfreaks.com/topic/16911-insert-template/#findComment-74512 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.