How To Create Hello World Smarty Template

How To Create Hello World Smarty Template Now that you have Smarty in place and the directories created, you can write your first Smarty page.You will convert this pure PHP page to a template: Hello The template for this should be located at /data/www/www.example.org/templates/ hello.tpl and will look like this: Hello {$name} By default, Smarty-specific tags are enclosed in brackets ({}). The PHP page hello.php file that uses this template looks like this: require_once ‘Smarty_ExampleOrg.php’; // Your Specialized Smarty Class $smarty = new Smarty_ExampleOrg; $name = array_key_exists(‘name’, $_COOKIE) ? $_COOKIE[‘name’] :‘Stranger’; $smarty->assign(‘name’, $name); $smarty->display(‘index.tpl’); Note that $name in the template and $name in hello.php are entirely distinct.To populate $name inside the template, you need to assign it to the Smarty scope by performing the following: $smarty->assign(‘name’, $name); Requesting www.example.org/hello.php with the name cookie set returns the following page: Hello George
CoOl. Powered by Blogger.