Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Hi,

Embedded snippets work really well, except that they don't appear as editable in the admin UI.

I need to have a reusable block of code (for instance, an image carousel) that I can inject into different pages, so that the client can simply edit all the carousels in one place in the backend.

So I have created the block of carousel code and saved it as a template 'frise.php'. It uses repeatables, shows up fine in the backend, and can be edited.

Unfortunately I can't figure out how to inject 'frise.php' into 'presentation.php' and other templates of my site. I can't seem to get it to work using masterpage. I keep getting a 'masterpage frise.php not found' error. I'm guessing I'm doing it all wrong :(

I'm sure it's quite simple. Can anyone help? Many thanks!
Ric
Hi,

what you probably is trying to achieve is have a reusable editable field.

Try creating a snippet, frise.html and put there only definition of an editable, nothing more:
Code: Select all
<cms:repeatable blabla>
   <cms:editable type='image' blabla />
</cms:repeatable>

Once you are done with that, you can embed this snippet (put it into snippets folder) in any other template:
Code: Select all
<cms:template blabla>
         .. other editables ..

          <cms:if "<cms:exists 'frise.html' />" ><cms:embed 'frise.html' /></cms:if>

</cms:template>

Thanks.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Hi, thanks a lot for the reply. Unfortunately it doesn't work as I would hope. I have the snippet embedded in two different templates now, using your technique, and I can see the image carousel in the backend, in each one.

However, they appear to be completely independent of each other. So if I add an image to the carousel in one template, it doesn't affect the other one at all. Neither in the backend, nor the web view.

What I wanted was for my client to be able to add/remove images to a carousel "in one place" in the backend, and have them be updated automatically in any template where the carousel "snippet" (or some other form of include?) is present.

Is this even possible, do you think? Thanks!
Here's how I would handle it.

Create a non-executable template for your carousel, frise.php.
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
   <cms:template title='Frise' executable='0'>
      <cms:repeatable name='my_repeatable'>
         <cms:editable name='my_image' type='image' />
      </cms:repeatable>
   </cms:template>
<?php COUCH::invoke(); ?>


Create a snippet in the snippets folder, frise.html. Whatever markup you use for the carousel will be added to frise.html.
Code: Select all
<cms:pages masterpage='frise.php'>
   <cms:show_repeatable 'my_repeatable'>
      <cms:show my_image />
   </cms:show_repeatable>
</cms:pages>

Now, wherever you want to include the carousel, you simply embed frise.html.
Code: Select all
<cms:embed 'frise.html' />
Editable can be placed in any template, no need to create a separate template. It can be done with separate though, np.

If it is not in separate template, set pages tag to limit='1'. So the thing is not duplicated on clonable templates.
This will save you a question if you decide to put that editable in the place you want to put it, not a new template on a sidebar.
Code: Select all
<cms:pages masterpage='here-put-template-with-editable.php' limit='1'>
   <cms:show_repeatable 'my_repeatable'>
      <cms:show my_image />
   </cms:show_repeatable>
</cms:pages>
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Thanks guys for your suggestions. I finally made it work using Tim's technique. Fantastic!

Ric
6 posts Page 1 of 1