Custom content via Logic Tab
Posted: Sun Mar 13, 2016 10:21 pm
There are other ways of doing this, but this example gives you insight into dynamic execution of smarty tags.
So the idea here is; keep a single template but allow custom content to appear via smarty tags that are specified in the "Smarty data..." entry on the "Logic" tab of your content page editor. For example we want to put some form data on a page. One might create a new template and put the smarty tag after the content definition
However this approach creates a never ending list of templates that may need maintenance over time and it would be nice to reduce this to only a handful.
So here is how I approached this problem.
First you need to set up a User Defined Tag:
name: dynamic_smarty
Code:
In your template put the following code before or after your content. You could create a variable to decide but we want to keep this simple for the example:
So let say our content is defined by:
Let us put out custom content after with this code:
So far so good, now we need to add the custom content to the page.
In your page content->Logic->"Smarty data or logic that is specific to this page:"
Place the following code:
Now when this page gets displayed it will also get the form output as defined by my form template 'my-form'.
I hope this helps people realise just how smart smarty tags are.
It would also be nice if this example was put into the documentation of User Defined Tags.
So the idea here is; keep a single template but allow custom content to appear via smarty tags that are specified in the "Smarty data..." entry on the "Logic" tab of your content page editor. For example we want to put some form data on a page. One might create a new template and put the smarty tag after the content definition
Code: Select all
...{$main_content nocache}...
{FormBuilder form='my-form'}...
So here is how I approached this problem.
First you need to set up a User Defined Tag:
name: dynamic_smarty
Code:
Code: Select all
$smarty->display('eval:'.$params['smarty_data']);
So let say our content is defined by:
Code: Select all
{$main_content nocache}
Code: Select all
{if isset($customcontent)}
{dynamic_smarty smarty_data="$customcontent"}
{/if}
In your page content->Logic->"Smarty data or logic that is specific to this page:"
Place the following code:
Code: Select all
{$customcontent = "{FormBuilder form='my-form'}"}
{share_data scope=parent vars='customcontent' scope=global}
I hope this helps people realise just how smart smarty tags are.
It would also be nice if this example was put into the documentation of User Defined Tags.