Hi,
I want to do a script which should be template changeable script. Something like wordpress.
Can you guide me how to do that?
Template based custom site
Moderator: General Moderators
- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: Template based custom site
Firstly, if you get any experts telling you that template parsing in PHP is "redundant/pointless/fubar" ignore them
Template parsing is invaluable in situations where you don't want to include larges amounts of HTML in your PHP scripts (and vice versa) or you want to use a range of different page designs from within the same scripts. Using template parsing you can also make parts of your template contextual or repeat - look at the phpBB source code if you want to see a good example of this kind of thing in action.
I wrote a template-parsing script a while ago and the way it works is that the template file is loaded into a variable and then each line is split into separate array values using explode().
The script then steps through each line and checks to see whether any values in the template look like this
{page_title}
and if they do it then replaces it with a value from
$GLOBALS['page_title']
using preg_replace(). As may be obvious, if you create a function in one of your scripts that creates all the menu links and you append all the menu code into one global variable, you can generate whole sections of code dynamically and then insert them into your template.
When all the lines of the template have been parsed, implode() is then used to append all the array values back into a single variable which you can then echo() back to the browser.
Is that the kind of thing you mean?
HTH,
Mecha Godzilla
I wrote a template-parsing script a while ago and the way it works is that the template file is loaded into a variable and then each line is split into separate array values using explode().
The script then steps through each line and checks to see whether any values in the template look like this
{page_title}
and if they do it then replaces it with a value from
$GLOBALS['page_title']
using preg_replace(). As may be obvious, if you create a function in one of your scripts that creates all the menu links and you append all the menu code into one global variable, you can generate whole sections of code dynamically and then insert them into your template.
When all the lines of the template have been parsed, implode() is then used to append all the array values back into a single variable which you can then echo() back to the browser.
Is that the kind of thing you mean?
HTH,
Mecha Godzilla