Forum for discussing general topics related to Couch.
10 posts Page 1 of 1
I'd like to have an admin-page ("settings.php") which should display all the main-pages on the site, next to a checkbox.

If this checkbox is checked, i'd like to include a special snippet in the code on that page. How do i code this? :?
1. Display a list of pages/templates as checkboxes in a template.
For that you can use the techniques described at viewtopic.php?p=2483#p2483.
The example code is for dropdown but works for checkboxes as well.

2. Get the selected values from the template above in other templates -
Use the staple <cms:pages> (or even <cms:get_field> viewtopic.php?f=5&t=11105#p28864) to do this and then depending on the result show or skip the snippet.

Hope this helps.
Thx, will experiment with that,

Question: I can not use <cms:pages since i want all of the pages in couch (not the cloned ones)

Edit: Perhaps i should say "all templates" instead of all of the pages
Code: Select all
 I can not use <cms:pages since i want all of the pages in couch (not the cloned ones)

In that case, wouldn't it be better to add a single checkbox to each of those pages (as opposed to configuring them all from a single location)?
Hmm, that could work, I'll try!

in the example you linked to https://www.couchcms.com/forum/viewtopic.php?p=2483#p2483

could i use

<cms:templates and an editable with opt_values dynamic

instead of <cms:pages ?
You can use any Couch tag - basically anything that outputs '|' (pipe) separated values for the options.
o.k, so,i'd put in something like this:

Code: Select all
<cms:templates show_hidden='0'>
    <cms:if k_template_is_executable='1'>
   
      <cms:editable name="template_chk" label="Include snippet" desc="Check all applicable"
             opt_values='<cms:show k_template_title /> |'
             type='checkbox'
        />
      
   </cms:if>
</cms:templates>


in my settings.php

but how do i check in each of the templates for this if one of the pages are checked (if i should include a snippet) ?

Code: Select all
<cms:get_custom_field 'template_chk' masterpage='settings.php' />


away form the computer, but will try later
o.k, so now i've been trying this at my computer.

I've added

this in the top

Code: Select all
<cms:editable name="display_musicplayer" label="Show Musicplayer in footer?" opt_values='Yes | No' type='radio' /> 


and this

Code: Select all
  
<cms:set my_opt = "<cms:get_custom_field 'display_musicplayer' />" />
<cms:if my_opt = 'Yes'>
      embed player...
</cms:if>


around the div where the player should be placed

and it seems to work, except for one thing: opt_values is displayed at the top of the template. Why?
opt_values is displayed at the top of the template

I take it that means the value(s) selected in the checkbox is being outputted on the page on the front-end (please correct me if I got it wrong).

To fix that please see this -
viewtopic.php?p=13407#p13407
Yes, that did it!

Thank you!
10 posts Page 1 of 1