Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
I have tried to look all over the forums for some answer to this question, but couldn't find any.

Is there anyway, snippets (embeddable html files), could be edited from the admin panel?

Thank you
Hi,

Physical files (like the snippets you mentioned) cannot be directly editing through Couch.

However, there is an alternative method that can provide this editing facility.
Basically suppose you have an snippet called 'footer.html' and this is how it is being used in any template
Code: Select all
<cms:embed 'footer.html' />

This is the how the cms:embed tag is most commonly utilized (i.e. with physical snippet files). The cms:tag, however, also allows passing it the code directly as its parameter (please see http://www.couchcms.com/docs/tags-reference/embed.html for details).

What we can do is, use a separate template (say named 'snippets.php') and define within it editable regions to hold the code that was contained within the snippet files (i.e. instead of using physical snippet files, we'll be placing their codes within these editable regions).

So, carrying forward our example, the snippets.php template can have the following region instead of the footer.html snippet mentioned earlier -
Code: Select all
<cms:editable 
    name='footer'
    label="Footer HTML"
    height='100'
    no_xss_check='1'
    type="textarea"
/>

Please notice that the type of the region defined is 'textarea' and its no_xss_check parameter is set to 1.
All the code from the footer.html snippet can now be moved into this region.

Finally, to use the code in other templates, the cms:embed statement can be modified to become the following -
Code: Select all
<cms:embed code="<cms:get_custom_field 'footer' masterpage='snippets.php' />" />

The output should be just the same as using snippet files.

Using this method allows us to edit the snippet codes right from the admin-panel. It'd be a good idea to set the permission on the snippets.php template to super-admin as you wouldn't want the client to mess up with your markup. The template can also be defined as being non-executable (by setting the executable parameter to '0') because it won't be accessed directly.

Hope this helps. Do let me know.
Thanks.
Thanks a bunch KK, will try it and let you know how it goes!
Thanks.

I'd like to add to my original post that using cms:embed tag to display back the editable contents would be required only if your snippets contain Couch tags (e.g. cms:show, cms:php etc.).

If the snippets happen to be only plain HTML, then the following statement alone would suffice
Code: Select all
<cms:get_custom_field 'footer' masterpage='snippets.php' />
KK, I have tried using the method you described above but the content is not showing. Is the snippets page supposed to be clonable?
Hi,

For our current purpose the snippets.php template has to be a non-cloned template.

Using the cms:get_custom_field tag to fetch data from editable regions is actually a standard technique (http://www.couchcms.com/docs/tags-refer ... field.html)
so the code I mentioned should definitely work -
Code: Select all
<cms:get_custom_field 'footer' masterpage='snippets.php' />

Please make sure that the parameters being supplied are correct.
6 posts Page 1 of 1