• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Custom content via Logic Tab
PostPosted: Sun Mar 13, 2016 10:21 pm 
Offline
New Member
New Member

Joined: Sun Mar 13, 2016 8:17 pm
Posts: 2
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
Code:
...{$main_content nocache}...
{FormBuilder form='my-form'}...

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:
Code:
$smarty->display('eval:'.$params['smarty_data']);


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:
Code:
{$main_content nocache}

Let us put out custom content after with this code:
Code:
{if isset($customcontent)}
    {dynamic_smarty smarty_data="$customcontent"}
{/if}


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:
Code:
{$customcontent = "{FormBuilder form='my-form'}"}
{share_data scope=parent vars='customcontent' scope=global}


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.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Custom content via Logic Tab
PostPosted: Mon May 09, 2016 4:23 pm 
Offline
New Member
New Member

Joined: Sun Mar 13, 2016 8:17 pm
Posts: 2
Nobody picked up, or could be bothered to point out, the slight incorrectness of my post. Whilst it would all work, dynamic smarty execution would not occur with the code I presented.

Quote:
Code:
{$customcontent = "{FormBuilder form='my-form'}"}
{share_data scope=parent vars='customcontent' scope=global}


The above $customcontent variable would acutaully hold the result of the smarty execution of {FormBuilder ....} because it is enclosed in double-quotes. In order for it to hold the smarty tag to dynamically execute it would need to be single quoted.

Therefore the correct code should look like this:
Code:
{$customcontent = '{FormBuilder form="my-form"}'}
{share_data vars='customcontent' scope=global}


Of course both give the same result, the only difference is the order of execution of the smarty tag {FormBuilder ...}

In the original example the {FormBuilder ...} smarty tag would get executed at the beginning of the template (via tag {process_pagedata}) and the result would be passed through to the {dynamic_smarty ...} tag which would find no smarty tags to execute and simply pass on the HTML to the output.

In the correction example here, the {FormBuilder ...} smarty tag would get executed via {dynamic_smarty ...} tag in the content part of the template.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Custom content via Logic Tab
PostPosted: Mon May 09, 2016 7:48 pm 
Offline
Dev Team Member
Dev Team Member

Joined: Mon Nov 28, 2011 9:29 am
Posts: 3007
Location: The Netherlands
Quote:
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.

Consider reading about Template Inheritance: http://www.cmscanbesimple.org/blog/the- ... gn-manager


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting