Use module template output in multiple content blocks

  Previous article Next article  

Use module template output in multiple content blocks

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.3.1
  Last updated: 17-09-2016
  Comments: 0

This page is on a desktop screen built with two columns. The main column where this text from the CGBlog detail template is displayed, and a sidebar on the right with other static content. But the data in the grey box on the right is also generated by the CGBlog detail template!

Note: This article is written for the CGBlog module, but can be used for all modules!

  How to use

In order to use this method the default {content} block has to be parsed by the Smarty template engine in the top of the Core::Page template. Read the following article for a more extended tutorial: Base CMS Made Simple page template with automated metatags.

Example Core::Page template
{strip}
    {$content = "{content}" scope=global} <------ Pay attention
    {$content2 = "{content block='content2' label='Sidebar'}" scope=global}
{/strip}<!DOCTYPE HTML>
<html lang="en">
    <head> </head>
    <body>
        <header> </header>
        <nav> </nav>
        <main>
            {$content} <------ Pay attention
        </main>
        <aside>
            {$content2}
        </aside>
        <footer> </footer>
    </body>
</html>

At this point it isn't that difficult... Assign the content you want to use in another content block in the modules detail template to a global Smarty parameter.

Capture the parts you want to "export", in example:

{capture assign='content_for_sidebar'}
  <div class="text-block">
    <h3>Title: {$entry->title}</h3>
    <p>Author: {$entry->fields.Author->value}</p> {* Custom field *}
  </div>
{/capture}

{$content_for_sidebar = $content_for_sidebar scope=global}

The code has to be in the detail template, it makes no difference if it is in the top or the bottom of the template... But now that I think about it, you can also use this for summary templates of course.

Read the following article for a more extended tutorial: Smarty scope examples.


A2 Webhosting CMS Made Simple

On the default and hidden detail page with two content blocks you call the exported content by adding in the sidebar content block:

{$content_for_sidebar}

That should do it!


Ohw, just in case your detail page is NOT hidden, the generated output can give a PHP Notice because the parameter isn't set. Prevent this by adding:

{$content_for_sidebar|default:''}

A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  0 Comments

No comments yet...

CMS Made Simple 2.2.3.1 - Tutorials, tips and tricks - CMSMS 2.2.3.1

Use module template output in multiple content blocks

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.3.1
  Last updated: 17-09-2016
  Comments: 0

A2 Webhosting CMS Made Simple