MENU

Use module template output in multiple content blocks

  Previous article Next article  

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.

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:''}

Buy Me A Coffee


  Comment Form

ReviewManager

Click here to open the form

ReviewManager

  0 Comments

No comments yet...

Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

Use module template output in multiple content blocks

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.19
  Last updated: 23-06-2018
  Comments: 0
  http://cms.ms/yovH


Buy Me A Coffee




Advertisement


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!