Use module template output in multiple content blocks
Previous article Next articleThis 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
{$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:
<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:
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:
Comment Form
ReviewManager
ReviewManager
0 Comments
No comments yet...