O'Reilly logo

Learning PHP, MySQL, and JavaScript by Robin Nixon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Templates

Now you need to write a simple Smarty template file to test whether everything is working, so type in Example 12-2 and save it in a file named index.tpl in the temp/smarty/templates directory you created earlier.

Example 12-2. The index.tpl template file
<html>
    <head>
        <title>{$title}</title>
    </head>
    <body>
        This is a Smarty Test
    </body>
</html>

As you can see, this is simply an HTML file with a .tpl file extension. But note the use of the Smarty variable {$title} on the third line. This is the same variable that was defined in Example 12-1. Smarty will substitute the value of the variable instead of the text in Example 12-2, because of the surrounding curly braces {} (see Figure 12-1).

The output from index.tpl in
Figure 12-1. The output from index.tpl in Example 12-2

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required