whiteknight Posted August 18, 2006 Share Posted August 18, 2006 Hi Folks (1st time poster here!) I am a .ASP website programmer (boo hiss) but am going to move into php, mainly for the cheaper webhosting and MySQL features. But I have a query. I currently use an .html template stored on my server and then I have a buildpage script which I call when I am creating standard pages, and just add it to my .asp pages. (default.asp etc etc) So they are created within the template, and thus all look the same, and everyone lives happily ever after.The buildpage script, replaces a line of text (XXXPAGECONTENTXXX) with the contents of the smaller .asp content page. I was wondering if one of you guys could help me out with a .php counterpart that I could replace my buildpage.asp with. (Obv the other pages will need tweaking to work, but this is the main milestone for me) Some help would be really appreciated! ( buildpage.asp below )Cheers guys------------- Buildpage.asp ------------------[code]<%'------------------------------------------'CREATE PAGE SECTION STRINGS FROM TEMPLATE'------------------------------------------Function ReadFromTemplate(strTemplateLocation, aryPageTemplate) '------------------------------------ 'LOOP THROUGH TEXT FILE CONTENT '------------------------------------ strTemplateLocation = "skin_default/template2.html" Set objFileSystem = CreateObject("Scripting.FileSystemObject") Set objFile = objFileSystem.GetFile(server.MapPath(strTemplateLocation)) Set objTextStream = objFile.OpenAsTextStream(1,0) strPageBaseText = objTextStream.ReadAll set objTextStream = nothing set objFile = nothing set objFileSystem = nothing '------------------------------------ 'FORMAT PAGE HEADER STRING '------------------------------------ 'Finally split the HTML into two pieces one for either side of the main page content aryPageTemplate = split(strPageBaseText,"xxxPAGECONTENTxxx",-1) ReadFromTemplate = aryPageTemplateEnd Function%>[/code]Then I simply put this at the top of my other pages[code]<%@ LANGUAGE="VBSCRIPT" %><% '-----------------------------------------------'NEED THIS INCLUDE FILE FOR EVERY PAGE'-----------------------------------------------%><!--#include file="buildpage.asp"--><%'-----------------------------------------------'READ PAGE TEMPLATE FROM FILE'-----------------------------------------------Call ReadFromTemplate(strTemplateLocation, aryPageTemplate)'-----------------------------------------------'WRITE FIRST HALF OF PAGE HTML'-----------------------------------------------response.write(aryPageTemplate(0)) %>*** PAGE GOES IN HERE ****** THEN THIS BIT AT THE END OF THE PAGE ***<%'-----------------------------------------------'WRITE LAST HALF OF PAGE HTML'-----------------------------------------------response.write(aryPageTemplate(1))%>[/code] Link to comment https://forums.phpfreaks.com/topic/17933-buildpage-script-using-html-template-file/ Share on other sites More sharing options...
gerkintrigg Posted August 18, 2006 Share Posted August 18, 2006 um..I might be wrong, but if you're trying to create hard static pages (IE export to a folder as an HTML file), you are probably not going to get a good answer out of me. (sorry). But if you're doing it all at runtime, you could just split the page in half (coz you're kinda doing that in script anyway) and include / require each bit...So: <?php // $root is the path to the root directory for this folder and keeps all links relative.$root='../';include $root.'top.php';?>My text stuff goes here... possibly imported from a $variable<?php echo '$root.'bottom.php';?> Link to comment https://forums.phpfreaks.com/topic/17933-buildpage-script-using-html-template-file/#findComment-76711 Share on other sites More sharing options...
ToonMariner Posted August 18, 2006 Share Posted August 18, 2006 I think what you did before was a string replacement - in which case you would have to read the file contents into a string and perform teh string replace...If instead of leaving placeholders to perform teh replacement on, you could save you template files as php files and replace xxxPAGECONTENTxxx with <?php echo $pagecontent; ?>.Now in your script you coudl do..$pagecontent = "A string grabbed from a databse or what ever.";require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/cont_template.php');obviously cont_template.php is the template file you have designed....... Link to comment https://forums.phpfreaks.com/topic/17933-buildpage-script-using-html-template-file/#findComment-76718 Share on other sites More sharing options...
whiteknight Posted August 18, 2006 Author Share Posted August 18, 2006 [quote author=gerkintrigg link=topic=104735.msg417943#msg417943 date=1155907195]um..I might be wrong, but if you're trying to create hard static pages (IE export to a folder as an HTML file), you are probably not going to get a good answer out of me. (sorry). But if you're doing it all at runtime, you could just split the page in half (coz you're kinda doing that in script anyway) and include / require each bit...So: <?php // $root is the path to the root directory for this folder and keeps all links relative.$root='../';include $root.'top.php';?>My text stuff goes here... possibly imported from a $variable<?php echo '$root.'bottom.php';?>[/quote]Hmm I think I know where you are going. Yeah I'm doing it all at runtime, the template is stored in a folder, and then the middle section of all the pages are created seperatly, so when I upload and link to say page1.asp (it is only the middle section) it has the build page script at the top and the browsers generate the full page without me having to create them each time., the site is www.cmdclan.co.uk if ur interested. Link to comment https://forums.phpfreaks.com/topic/17933-buildpage-script-using-html-template-file/#findComment-76805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.