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.
<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).
Get Learning PHP, MySQL, and JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.