by
KK » Sun Jul 12, 2015 9:42 pm
Hi Brian

The cms:pages tag, unfortunately, supports only a single 'masterpage'.
However, there is another tag in Couch 'cms:query' than can be used to execute raw SQL statements. We can use this to fetch pages from multiple masterpages, for example as follows where we use two templates 'actors.php' and 'movies.php' -
- Code: Select all
<cms:query
sql="SELECT p.id, p.template_id
FROM <cms:php>echo K_TBL_PAGES;</cms:php> p
inner join <cms:php>echo K_TBL_TEMPLATES;</cms:php> t
on p.template_id = t.id
WHERE (t.name='actors.php' or t.name='movies.php')
AND publish_date < '<cms:date format='Y-m-d H:i:s' />'
AND NOT publish_date = '0000-00-00 00:00:00'
ORDER BY publish_date desc;"
limit='10'
paginate='1'
fetch_pages='1'
>
<!-- variables from the pages fetched available here exactly like in cms:pages -->
<a href="<cms:show k_page_link />"><cms:show k_page_title /></a><br />
</cms:query>
The only line in the SQL code above that you need to change is the following where you can add your own templates -
WHERE (t.name='actors.php' or t.name='movies.php')
e.g. add a third template
WHERE (t.name='actors.php' or t.name='movies.php' or t.name='directors.php')
Please also note that it is likely the templates will have regions of different names so you'll need to make a check of each fetched page's masterpage before displaying its variables e.g. as follows -
- Code: Select all
<cms:query
sql="SELECT p.id, p.template_id
FROM <cms:php>echo K_TBL_PAGES;</cms:php> p
inner join <cms:php>echo K_TBL_TEMPLATES;</cms:php> t
on p.template_id = t.id
WHERE (t.name='actors.php' or t.name='movies.php')
AND publish_date < '<cms:date format='Y-m-d H:i:s' />'
AND NOT publish_date = '0000-00-00 00:00:00'
ORDER BY publish_date desc;"
limit='10'
paginate='1'
fetch_pages='1'
>
<h3><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></h3>
<cms:if k_template_name='actors.php'>
.. show regions from actors.php ..
<cms:else_if k_template_name='movies.php' />
.. show regions from movies.php ..
</cms:if>
<cms:paginator />
</cms:query>
Hope it helps.