What are the advantages and disadvantages of using a template system like Smarty in PHP development?

Using a template system like Smarty in PHP development can help separate the presentation layer from the business logic, making the code more maintainable and easier to work with for designers and developers. It also allows for reusability of code snippets and provides built-in security features to prevent common vulnerabilities like XSS attacks. However, using a template system can add an extra layer of complexity to the project and may require additional time to learn and implement.

// Example of using Smarty template system in PHP
require_once('smarty/Smarty.class.php');

$smarty = new Smarty();
$smarty->template_dir = 'templates/';
$smarty->compile_dir = 'templates_c/';

$smarty->assign('title', 'Hello, World!');
$smarty->assign('content', 'This is a sample content.');

$smarty->display('index.tpl');