In a previous post (viewtopic.php?f=4&t=9476), I recommended using a cms:if conditional block inside a 'message' type editable region to hide the Advanced Settings tab from ordinary administrators in the admin panel. In my own experiments, I had found that Couch tags work normally in 'message' regions allowing quick and easy template-based modifications to the admin panel.
Code: Select all
<cms:editable name='hide' type='message'>
    <!-- Only super admin can see Advanced Settings -->
    <cms:if k_user_access_level lt '10'>

@KK corrected me saying that the code would not be parsed by Couch but merely injected literally onto the page.
KK wrote: The correct implementation would be as follows -
Code: Select all
<cms:editable name='hide' type='message' dynamic='default_data'>

You'll also need to create a snippet named 'hide.html' and place it in your couch/snippets folder.
Place the following within the snippet -
Code: Select all
<cms:if k_user_access_level lt '10' >

Now the contents of the message region are dynamic - every time the edit page is accessed, the region tries to find a snippet named 'hide.html', execute it and inject the content returned by the snippet in the admin-panel.

You can find this technique being used to conditionally inject JavaScript in the admin-panel -

With further testing, I discovered (no surprise) that @KK was right. Couch conditionals don't work properly in the 'message' region. More than that it seems to break something in a profound way.

After trying the cms:if block in a test template, it not only didn't create the desired output; when I removed the code from the template - or changed another editable region - the template failed to update. Instead, each time I visited the page as Super Admin, it seemed to add another loop through the Couch data. I could see this in a cms:dump_all tag where another _ROOT_ section was added to the output for each page refresh.

However, it's only the conditional statement that seems to cause trouble. Other cms tags appear to work normally, for instance cms:link tags and cms:pages loops. Even cms:php code seems to output correctly.

The test template I used includes a variety of styling and scripting tests. All but the cms:if statement seem to work fine.
Code: Select all
<?php require_once( 'manage/cms.php' ); ?>
<cms:template title='Test Page' >
    <cms:editable name='admin_hacks' type='message'>
        <!-- CSS -->
        <style>.k_element{border:1px solid red;}
        <cms:ignore> ## PROBLEMATIC CODE. Uncomment to test
            <cms:if k_user_access_level lt '10' >
        <!-- JS -->
        <script>document.write("<p>Hi there! I'm JavaScript.</p>");</script>
        <!-- PHP -->
        <cms:php>echo '<p>Hello from PHP!</p>';</cms:php>
        <!-- Couch Admin Links -->
        <!-- You can link to other admin pages using Couch tags -->
        <cms:pages masterpage='index.php'>
            <p><a href="<cms:admin_link />">Edit Home Page</a></p>
        <!-- Link to clonable template -->
        <cms:pages masterpage='gallery.php' limit='1'>
            <p><a href="<cms:show k_admin_link /><cms:show k_admin_page/>?act=list&tpl=<cms:show k_template_id/>">Edit Gallery</a></p>
        <!-- More Couch Tags. They all seem to work.-->


<h1>This is a test page.</h1>
<?php COUCH::invoke(); ?>

So I'm curious about the details of the dynamic="default_data" setting. Does it only have to do with conditional statements? What does it affect and does the data always have to be loaded through an embedded snippet? And what's happening with the cms:if statement? In this test, it doesn't get parsed literally; instead it seems to create a growth like a cancer.

In 99% of cases, the admin panel is perfect as-is. But since Couch has the power and flexibility, it's good to know how to tweak and customize it. Even with the new admin panel customizations available through data-bound forms and the upcoming admin panel redesign, I think that 'message' region hacks will continue to be useful for quick fixes and simple customizations, and even for more complex Admin Panel features. I'd be interested to understand it better, particularly when it comes to using Couch tags.