$smarty = new Smarty(); $smarty->assign('name', 'John'); $content = $smarty->fetch('sub-template.tpl'); echo $content;
$smarty = new Smarty(); $smarty->assign('title', 'My Page'); $smarty->assign('content', 'Welcome to my page!'); $smarty->assign('sidebar', $smarty->fetch('sidebar.tpl')); $smarty->assign('footer', $smarty->fetch('footer.tpl')); $content = $smarty->fetch('main-template.tpl'); echo $content;In this example, the fetch function is used to fetch the content of two sub-templates named `sidebar.tpl` and `footer.tpl` and assign them to the variables `$sidebar` and `$footer` respectively. These sub-templates are then included within a main template named `main-template.tpl` using the `$smarty->fetch` function. The `assign` function is used to assign the values 'My Page' and 'Welcome to my page!' to the variables `$title` and `$content` respectively, which can be used within the main template. Package Library: Smarty is a standalone library, however, it can be used with a variety of PHP frameworks and content management systems such as Laravel, Magento, WordPress, and more.