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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.