Hi guys,
its me again. How do you write templates for your sites (without template engine)? Pure php or what? I want to hear how you do it

Recommended Answers

All 4 Replies

Member Avatar for diafol

IF you want a good robust and QUICK templating system, get something like Smarty. I tend to use Rain TPL due to its small size.

I've also developed my own templates, but these tend to be static-ish include files. Without using a templating system, I don't think there's a very reliable way of mixing html and php without using the echo/print commands - which can get very messy. The heredoc function allows the printing of plain text with variables, but this is not exactly the same thing.

Using templating systems can seem wasteful - at least two files as opposed to one, but for large projects they are invaluable. Used along with database abstraction, they save so much time when you need to edit something.

How difficult is learning Smarty, at least comparered to your beloved Rain TPL?

Member Avatar for diafol

It's not that difficult. I like the way templating systems allow you to separate php code and html. You can even nest template pages (like php include files).
The systems allow loops and conditionals to be placed directly within the html so that not everything has to be created solely within the php file. For example:

{if $user<>''}
<p>Welcome {$user}</p>
{else}
<p>Welcome - not a member?  Join up for free!</p>
{/if}

The curly brackets show Smarty commands, statements and variables within the html page. Notice that the $user variable doesn't require an echo/print.
It is passed to the html page from the php page.

Smarty installs easily and has got quite a lot of online help. Rain TPL's help system is considerably less developed, but I find it less burdensome. However, I probably would struggle with Rain TPL had I not used Smarty and familiarised myself with templating systems.

For small projects, I'd stay clear of templating, but large-scale projects really do benefit from their use.

i have no idea about this because i am new in this.. and i am trying to get information here. its really very informative site. it also very useful and helpful for us.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.