by
KK » Sun Apr 05, 2015 1:15 am
Hi Klaus,
Can you please try out the following proposed solution and let me know if it works?
Taking the example of the templates using in the advanced tutorial (
http://www.couchcms.com/docs/advanced-tutorial/), suppose we wish to attach comments to the 'page_view' route of 'notes.php'.
The first step, as per normal, is to declare the template as commentable -
<cms:template title='Notes' clonable='1' routable='1' commentable='1'>
Next, again as per normal, we need to place the code for showing the comments form and displaying the comments (
http://www.couchcms.com/docs/concepts/u ... ments.html). This we do in the 'views/notes/page_view.html' snippet as this is the one handling the page-view.
The problem, as you have noticed, is that although the comment form displays fine, when we submit it Couch complains that this template is not commentable - this happens because commenting works only in native page-view (which we have seen is not applied by default when we make a template routable).
The proposed solution to this problem is this -
in the 'views/notes/page_view.html' snippet we are enforcing the page-view by explicitly fetching in the page (the 'rt_id' parameter) using cms:pages tag and then executing all code within its context -
<cms:pages id=rt_id limit='1' show_future_entries='1' >
<cms:set my_title=k_page_title 'global' />
<cms:capture into='my_content' >
..
</cms:capture>
</cms:pages>
<cms:embed 'views/layout_with_sidebar.html' />
We'll make a slight change to this arrangement. Instead of using the enclosing cms:pages tag block, we'll use the following instead -
<cms:php>
global $PAGE, $CTX;
$CTX->set( 'k_is_home', 0 );
$PAGE = new KWebpage( '<cms:show k_template_name />', '<cms:show rt_id />' );
);
$PAGE->set_context();
</cms:php>
<cms:set my_title=k_page_title 'global' />
<cms:capture into='my_content' >
...
</cms:capture>
<cms:embed 'views/layout_with_sidebar.html' />
As you can see, we have removed the enclosing cms:pages bloack and instead thrown in a bit of PHP right at the top of the snippet to set the context to page-view.
The result should be the same for the original code in the snippet but, importantly, now the commenting should also work.
For documentation sake, if the snippet happened to use the 'page_name' (instead of page_id'), as you are doing, the PHP code above would become as follows (assuming 'rt_page_name' querystring parameter contains the page-name) -
<cms:php>
global $PAGE, $CTX;
$CTX->set( 'k_is_home', 0 );
$PAGE = new KWebpage( '<cms:show k_template_name />', null, '<cms:show rt_page_name/>' );
$PAGE->set_context();
</cms:php>
Please try out and let me know if it helps.