Smarty : Use {block} in included files?

41 Views Asked by At

I'm mainly using twig as template engine for my projects. But for a project i need to use Smarty. So i'm new with this template engine. As far i know, in Twig, we can use embedded templates. Here the definition of an embedded template from the Twig documentation:

The embed tag combines the behavior of include and extends. It allows you to include another template's contents, just like include does. But it also allows you to override any block defined inside the included template, like when extending a template. Think of an embedded template as a "micro layout skeleton".

So, it's like including a subtemplate but the included subtemplate have different block tags reusables in the parent template.

Does something equivalent exists with Smarty?

I was thinking something like:

parent.tpl

<html>{block name='title'} {/block}</html>
<body>
{block name="content"} {/block}
</body>

main.tpl

{extends "parent.tpl"}
{block 'title'}my main page{/block}
{block 'content'}
    {include 'subtemplate.inc.tpl'}
    {block 'top_include'}...{/block}
{/block}

subtemplate.inc.tpl

{block name='top_include'}...{/block}

I know this is not working. But i'm looking for a way to accomplish my goal.In fact i want to reuse a modal component. Instead of rewrite the html code of the modal in each place where it will be used, i need to write the code once and call it from everywhere in my templates but changing only some small parts of the modal component (the title and some buttons).

0

There are 0 best solutions below