by
KK » Mon Aug 17, 2015 2:26 pm
Hi Pierre,
For showing data from regions defined in one template on other template, the trick is to bring the original page in context. Let me explain - suppose a text region named 'my_text' is defined in a template named 'contact.php'. To show its data on any other template (say 'index.php' or any other) we *cannot* simply use the following as 'my_text' won't be found -
- Code: Select all
<cms:show my_text />
What we need to do is to first bring contact.php into context and then call cms:show as follows -
- Code: Select all
<cms:pages masterpage='contact.php' limit='1'>
<cms:show my_text />
</cms:pages>
In the snippet above, we are assuming that contact.php is a non-clonable template.
The 'limit' set to '1' above is redundant for non-clonable templates (as they only ever have a single page). However, had it been a clonable template, without the 'limit' of one the code above would have looped through all its cloned pages and shown 'my_text''s value from each page.
So if you need to show data from one particular page of a clonable template (say 'blog.php'), we can additionally specify that cloned page's name e.g.
- Code: Select all
<cms:pages masterpage='blog.php' page_name='some-blog-entry' >
<cms:show my_text />
</cms:pages>
With that understood, you'll see that the method required for repeatable-regions is no different.
Normally we use the following for showing repeatable-region's data in the same template that defines them
- Code: Select all
<cms:show_repeatable 'my_repeatable'>
<cms:show 'my_text' />
</cms:show_repeatable>
To do so in another templates, the code now becomes the following (if the repeatable-region is defined in a non-clonable template, say, contact.php)
- Code: Select all
<cms:pages masterpage='contact.php' limit='1'>
<cms:show_repeatable 'my_repeatable'>
<cms:show 'my_text' />
</cms:show_repeatable>
</cms:pages>
Or the following (if the repeatable-region is defined in a clonable template, say, blog.php, where the code below will fetch data from a cloned-page named 'some-blog-entry')
- Code: Select all
<cms:pages masterpage='blog.php' page_name='some-blog-entry' >
<cms:show_repeatable 'my_repeatable'>
<cms:show 'my_text' />
</cms:show_repeatable>
</cms:pages>
Hope it helps.