Smarty scope examples
Previous article Next articleCMS Made Simple 1.12 introduces the concept of 'scopes' in Smarty templates. This version of Smarty does not treat each and every variable as a global. This will solve problems with Smarty variables being inadvertently overwritten, but will cause problems with websites that rely on some global variables.
About scope
Formerly, you could create a variable in a module template (for example the News detail template could set a canonical variable) and then use that variable in another template, such as in the portion of your page template. Though this is still possible, an additional step is required.
In a CMSMS Core::Page template there are 3 different scope areas
<head> <!-- Area 2 --> </head>
<!-- Area 3 -->
They are rendered in the order: 1, 3 and 2!
You need to add scope=global to your assigned parameter when you want to re-use the value in another scope...
CMS Made Simple 2.2 introduces a fourth scope!! All "mact" module action will be processed first. Therefor you need to process your content blocks containing the module tags (in the template head) first.
You can see here a base CMS Made Simple page template with automated metatags »
You can change this behavior with the "startup_mact_processing" config parameter!
More info at the CMSMS docs website
How to use
Templates
Current
New
{$content=$content scope=global}
Or a bit shorter:
Current
New
Current
{title assign=page_title}
New
{$page_title="{title}" scope=global}
Current
...
...
{/capture}
New
...
...
{/capture}
{$foo=$foo scope=global}
Current
New
Or a bit shorter:
Current
{$page_title = $entry->title}
New
{$page_title = $entry->title}
{share_data data='page_title,canonical' scope=global}
Stylesheets
Current
New
Current
New
Comment Form
ReviewManager
ReviewManager
3 Comments
Rolf, thnx for your reply! Also, this tag doesn't working with multiple excludes, for example: {RedirectCanonical canonical_url=$canonical_url exclude=''page-1,page-2'}
You can see a working example at this blog:
https://cmscanbesimple.org/blog/base-cms-made-simple-page-template-with-automated-metatags
Using the same word (for example content) for everything in your post makes it useless !
{content assign=content}
{$content=$content scope=global}
Is 'content' a reserved word, is it a variable name, and where ?