tags:

views:

63

answers:

4

i have seen many scripts where you'll see something like this

<meta keyword="{keywords}" ...>

or

<input type="text" name="name" value="{name}">

what is this called and how can i do this myself.

thanks

+5  A: 

It is called a template.

You need a template engine or you can write one yourself. A long time ago there was a popular template engine called Smarty. Today, template engines are part of most frameworks.

Here's a list of a few template engines for PHP: http://www.webresourcesdepot.com/19-promising-php-template-engines/

Considering the fact that you have such a question, your very own template engine will more likely have bugs, so I suggest choosing one of the freely available ones.

One more thing. PHP itself is a kind of template engine, so you do not necessarily have to add another level of templating. Use PHP:

<input type="text" name="name" value="<?=$VALUES['name']?>">
zilupe
this requires php short tags to be enabled. Without it, it will output literally, questions marks and all.
seanmonstar
A: 

There are templating engines out there that support this style of variable syntax, for example Blitz templates (http://alexeyrybak.com/blitz/blitz_en.html) comes to mind.

Jordan S. Jones
A: 

I am not sure what you mean, but let me take a wild guess:

$foo = "Please replace {this} here!";
$bar = str_replace('{this}', 'that', $foo);

Of course there are plenty of templating systems around that do exactly that, only much smarter. So you might wanna look into that.

n3rd
+1  A: 

can i recommend...

<input type="text" name="name" value="<?= e($name) ?>">

where e is an escaping function

i find template engines unnecessary

more examples...

foreach...

<ul>
<?php foreach( $items as $item ): ?>
    <li><?= e($item) ?><li>
<?php endforeach; ?>
</ul>

if....

<input type="checkbox"<?php if( $checkbox ): ?> selected="selected"<?php endif; ?>>
Galen
You should also recommend not using short tags. Unlike your examples.
random