Jump to content

Creating Templates


fusionpixel

Recommended Posts

I am creating a simple site that will be edited by several people and I would like to set up a simple sistem similar to what templates use

{header}

instead of

header()

I was looking at some template solutions but they are too big for what I am trying to acomplish. so in short I was wondering what is the best way to convert header() into {header}. Is there any simplified way to do it?

TIA
Link to comment
https://forums.phpfreaks.com/topic/29981-creating-templates/
Share on other sites

the regular armoury of PHP's search+replace functions will do the trick. in terms of templating, [url=http://www.php.net/preg_replace]preg_replace[/url] will do nicely, but be prepared to enter the murky world of regular expressions :)

however - there's plenty of info in the 'Regex board' here:
http://www.phpfreaks.com/forums/index.php/board,43.0.html

if its just templating to the point where you want to seperate your main code from your views, then it maybe worth taking a read through (my favourite!!!!) this:

http://www.massassi.com/php/articles/template_engines/

Hope that helps
Mark
Link to comment
https://forums.phpfreaks.com/topic/29981-creating-templates/#findComment-137749
Share on other sites

Humm, that seems interesting. I am familiar with regexp and will look more into that. At least with the reading I have made to the site you point me out to I have adjusted my template from

<? echo header(); ?>

to

<?=$header;?>

it think it will be easier for people to remember just to type <?=$header;?> but we will see.

I will look into how to replace the {} for actual content.

THX
Link to comment
https://forums.phpfreaks.com/topic/29981-creating-templates/#findComment-137755
Share on other sites

no worries.

what many coders that use template engines need to kinda realise is that, unless your coder is a donkey, typing <?=$header ?> really isnt too much harder than typing {header}. as that article explains, and as i've come to realise through my own toying around, PHP is a perfectly good templating engine itself. obviously beware of sites that have the short tags (like <? and <?=) turned off, but it seems to be on by default these days and signs suggest that even PHP6 will continue to support the short tags/alternative syntax (like foreach/endforeach, if/elseif/endif, etc)

good luck.
Link to comment
https://forums.phpfreaks.com/topic/29981-creating-templates/#findComment-137804
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.