The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

how2make {template}

How to make this {VAR1} where in place of "var1" echo a txt from that variable.
For exm. if i make script i want to allow someone can change template like he want by puting {some_predefined_var} like {date} or {author} etc.
if someone don't understand me, i want to make something like in CuteNews templates.

One thing I don't particularaly like about some of the templating methods out there is their choice of "tags" to look for in the template to replace. Often they'll use {} or [] which can show up in the web browser if not replaced properly by the contents. Instead I tend to use

Code:

<xMyTag/>

which at least the browser will interpret as an HTML tag and not display.

It can be as simple as defining what these tags are and then doing a simple str_replace() on the file contents.

This is how I do my templating. I've looked at things like Smarty and found them to be over complex. This is simple, and if its for someone other than myself, I'll create a simple document that lists the available tags that can be placed in a template and the type of data that will replace the tag.

In some projects, for example, one of the tags actually represented a table of about 150 rows. Now instead of having PHP do all the html, I start nesting these tags... I'll try and explain it here:

PHP Code:

// $data is an array containing the information pulled from a database
// $template contains the main page layout

// So at this point I have $formatted_rows containing the html formatted
// rows of all the data I want to display... Something like:
//
// <tr>
// <td>John</td><td>Smith</td>
// </tr>
// <tr>
// <td>Jane</td><td>Doe</td>
// </tr>
// Now we need to take these rows and drop them into the table template
// and then drop the table template into the main template and display the
// results