by
KK » Wed May 28, 2014 12:41 am
Thanks for the explanation, Brandon.
I'll try to make things clear for you.
Let us assume the index.php is non-clonable and has only one editable region (type richtext) - 'my_desc'.
Further assume that the events.php is also non-clonable and has one editable region (also type richtext) - 'my_event_desc'.
If we were to place the following code
in 'index.php' -
- Code: Select all
<cms:show my_desc />
<cms:show my_event_desc />
- I think you can guess that the contents of only 'my_desc' will show up. That is because 'my_event_desc' is not defined in the index template.
But if we change the code to following (again remember this code is in 'index.php') -
- Code: Select all
<cms:show my_desc />
<cms:pages masterpage='events.php' >
<cms:show my_event_desc />
</cms:pages>
- you'll see that the contents of 'my_event_desc' also show up.
The region between the opening and closing tags of cms:pages will have all the variables defined for 'events.php'.
In the rest of the template (that is index.php) we'll have variables belonging to index.php.
(Please note that events.php is non-clonable hence the cms:pages tag will loop only once - had the template been a cloned one, cms:pages would have looped as many times as there were cloned pages of the template. In which case, to target a particular page we could use the 'page_name' or 'id' parameter).As you can see, by using the cms:pages tag with the 'masterpage' parameter we can call, from within any template, data belonging to any arbitrary template.
Taking your case in particular, since the editable region is a repeatable-region, we'll use the regular syntax of accessing such data i.e. cms:show_repeatable. The code would become
- Code: Select all
<cms:pages masterpage='events.php' >
<cms:show_repeatable 'name_of_your_region'>
<cms:show some_contained_region />
</cms:show_repeatable>
</cms:pages>
Hope this clears things up.
Coming to your second question -
The other piece I am not clear on is: if a separate template PHP file is created (like I would do for events), does that PHP file need the CMS template strings AND the CMS strings to output HTML too? From there, the the PHP template file would be imported into the parent page?
Once again, I don't think I got you completely but I'll try -
See, events.php is a Couch managed template (else how would you make it show up in the admin panel and have editable regions defined in it?). To make a template Couch managed, it has to have a .php extension an also the two mandatory lines of code. So, the following could be the
complete code of a template -
- Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<?php COUCH::invoke(); ?>
Of course, it won't do anything except show the template's name in the admin-panel sidebar.
One would also want to define editable regions within the template so the full code could become this -
- Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Events'>
<cms:editable name='my_event_desc' type='richtext' />
</cms:template>
<?php COUCH::invoke(); ?>
If you access the template above via your browser, it'll show nothing. That is understandable as we are outputting nothing - only defining the solitary editable region.
In the admin-panel, however, it will show that editable region for inputting data.
So we are using the template above
only to get the data in. To get the data out, we can use the cms:pages tag (with masterpage set to this template) placed on any other template of the system (as discussed above).
Since, in the case above, we won't be using the template to display anything, it's better (but not mandatory) to declare it as 'non-executable' like this -
- Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Events' executable='0'>
<cms:editable name='my_event_desc' type='richtext' />
</cms:template>
<?php COUCH::invoke(); ?>
By doing this, if a non-admin tries to access the template via browser she'll be shown a 'page not found' message.
Hope this clears up things a bit