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

I'm not even sure that title makes sense but at least it has some of the right keywords in there!

I'm currently building another site using the excellent Couch and I have a request from the client. I'm wondering whether it can be solved quite cleverly or whether I'm asking too much of the system.

Essentially I have a list of adverts (image and url). These adverts will appear within the front end pages however I want to be able to control:
1) which adverts appear on which pages
2) the order of those adverts on each individual page

So as a very simple example, if I had 2 pages and 2 adverts I might want to have:

Page 1
- advert 1
- advert 2

Page 2
- advert 2
- advert 1


My idea for this (if it's possible) was to have a cloned template for the adverts (to avoid repetition when entering the adverts). I was then wondering if it's possible to use this cloned template to output additional fields on other specified CMS pages? I was thinking it would be good to have a repeatable region with all of the adverts listed and an option (checkbox) to turn them on and off for that page. The repeatable would also handle the ordering since it's built into the field.

So I just really need to know whether something like that would be possible or whether I'm barking up the wrong tree. Or if anyone's had a similar problem how you've gone about solving it?

Thanks
Daz
Hi Daz,

I think I understood the use-case.

Well, you've spelled out the complete solution yourself :)
I'll just show here how to implement it in Couch.

As an overview -
let us say we have a clonable template named 'advertisements.php' where each page of it is an advertisement.

Now on the other template (the front-page one that'll show the adverts), we'll create a repeatable-region with a single field - a dropdown list.

This dropdown list will show all the adverts we have (i.e. dynamically lists all the cloned pages of 'advertisements.php').
Untitled-1.png
Untitled-1.png (8.47 KiB) Viewed 7114 times

Now for each page, in the admin-panel you can simply create a row, select the right advert, re-arrange the rows (adverts) if required and that would be it.
Untitled-2.png
Untitled-2.png (6.5 KiB) Viewed 7114 times

On the front-end we'll use the selected values to fetch in the pages of 'advertisements.php' and display them.

OK? So here is how we do it (I am assuming your template for the adverts is named 'advertisements.php') -
Create a snippet (we'll name it 'my_adverts.htm') and place it in the snippets folder of Couch.
Put the following code within it -
Code: Select all
Please Select=-
<cms:pages masterpage='advertisements.php'>
   | <cms:show k_page_title  />=<cms:show k_page_id  />
</cms:pages>

Define a repeatable region in your template that'll show the adverts like this -
Code: Select all
<cms:repeatable name='my_adverts' label='Advertisements' >
    <cms:editable
        name="advert"
        label=":"
        opt_values='my_adverts.htm'
        dynamic='opt_values'
        type='dropdown'
    />
</cms:repeatable>

You should now see a list of all adverts while creating a page of this template.
Choose and arrange the adverts for each page.

Now to display the selected adverts on the front-end, add the following code to the template -
Code: Select all
<cms:if k_is_page>
    <h1><cms:show k_page_title /></h1>
   
    <cms:show_repeatable 'my_adverts' >
        <cms:if advert != '-' >
            <cms:pages masterpage='advertisements.php' id=advert limit='1'>
                <h3><cms:show k_page_title /></h3>
            </cms:pages>
        </cms:if>
    </cms:show_repeatable>
   
</cms:if>

The code above is simply showing the page title for the selected adverts - you should instead show the image and link data you have.

Hope this helps.
Do let us know.
Hi Kamran,

Thanks for this, it looks like a great solution! I'll be implementing it and some point this week and let you know how it goes.

Thanks
Daz
Hi,

I've had chance to implement this solution and it works perfectly. It's exactly what I had in mind so thank you so much for posting it! I didn't know it was possible to feed pages back into CMS fields and it's something that will open up a lot of options for me in the future.

Thanks again!
Daz
You are welcome, Daz :)
I am glad it helped.
I have a similar requirement to dzauk, but each of my 'ads' need to be one of 5 designs/layout options.

See: http://dev.lauraritchiedesigns.co.uk/cl ... ts.php?p=8

This is a client testimonial page, and my client wants to vary the layout of each testimonial to break it up visually and some photos will dictate portrait or landscape images etc

I have set this page up with repeatable regions, but it is cumbersome and when a row is added it is the same design as the previous one, the 'ad' scenario is a better option.

BUT, can it be created with my client choosing and/or changing the layout of each testimonial when they are being created and then choosing from a dropdown like the example above.

Or am I approaching this the wrong way, any thoughts…
Hi PixelAce,

To make clearer to others reading this thread as to what we'd be discussing - following are the various formats of the testimonials -
testimonials.png
testimonials.png (28.12 KiB) Viewed 6868 times

This is how I suggest you implement it.
1. The maximum number of images in any of the testimonial format is 4 so you need to define 4 'image' regions in the repeatable-regions. Since the dimensions of the images vary with the formats set 'height' and 'width' to some reasonable upper limit (e.g. 800) and use enforce_max='1' -
Code: Select all
<cms:editable name='my_image_1' width='800' height='800' enforce_max='1' input_width='200' col_width='200' type='image' />
<cms:editable name='my_image_2' width='800' height='800' enforce_max='1' input_width='200' col_width='200' type='image' />
<cms:editable name='my_image_3' width='800' height='800' enforce_max='1' input_width='200' col_width='200' type='image' />
<cms:editable name='my_image_4' width='800' height='800' enforce_max='1' input_width='200' col_width='200' type='image' />

2. Define a 'dropdown' with options for the 5 formats of testimonials e.g.
Code: Select all
<cms:editable 
      name='my_format_type'
      opt_values='First Format=1 | Second Format=2 | Third Format=3 | Fourth Format=4 | Fifth Format=5'
      type='dropdown'
/>
You can give more descriptive names to the formats above if you want (but leave the numbers after the equals_to sign as they are).

The client will enter the images and will select whatever format is desired for the row.

On the front-end we can check for the selected format and output the right HTML.
Code: Select all
<cms:show_repeatable 'region_name' >
    <cms:if my_format_type='1'>
        .. HTML for the first format here ..
    </cms:if>
    <cms:if my_format_type='2'>
        .. HTML for the second format here ..
    </cms:if>
    <cms:if my_format_type='3'>
        .. HTML for the third format here ..
    </cms:if>
    <cms:if my_format_type='4'>
        .. HTML for the fourth format here ..
    </cms:if>
    <cms:if my_format_type='5'>
        .. HTML for the fifth format here ..
    </cms:if>
</cms:repeatable>

For each of the formats, use the cms:thumbnail tag to produce the images of the required sizes e.g.
Code: Select all
<img src="<cms:thumbnail my_image_1 width='650' height='375' />" />
<img src="<cms:thumbnail my_image_2 width='209' height='375' />" />

To make the code more organized, you can create five snippets (for the five formats) and place the HTML generating code in them. Name the snippets file as (for example) 'testimonial_1.html', 'testimonial_2.html', 'testimonial_3.html' etc.

Our code can now become-
Code: Select all
<cms:show_repeatable 'region_name' >
    <cms:if my_format_type='1'>
        <cms:embed "testimonial_1.html" />
    </cms:if>
    <cms:if my_format_type='2'>
        <cms:embed "testimonial_2.html" />
    </cms:if>
    <cms:if my_format_type='3'>
        <cms:embed "testimonial_3.html" />
    </cms:if>
    <cms:if my_format_type='4'>
        <cms:embed "testimonial_4.html" />
    </cms:if>
    <cms:if my_format_type='5'>
        <cms:embed "testimonial_5.html" />
    </cms:if>
</cms:repeatable>

Since the snippet names match the format numbers, the code above can be made even more compact to become just this
Code: Select all
<cms:show_repeatable 'region_name' >
    <cms:embed "testimonial_<cms:show my_format_type />.html" />
</cms:repeatable>

Hope this helps.
Thanks for that, really useful.
Sorry to be a pain, but it's me again.
My client has now changed her mind, and everything I posted yesterday has been scrapped. The good news it's a lot simpler and follows very closely the 'advert' scenario that started this thread…
But I'm stuck, I have followed the guidelines and as far as I can see have replicated everything, but the page that should display the 'ads' doesn't pull anything in.
The drop downs with each ad work and can be specified and ordered.
Here's the code before the <head> for the page to display the ads…

Code: Select all
<cms:template title='Client Comments' order='70'/>
<cms:repeatable name='lauras_testimonials_list' label='testimonials_list' >
    <cms:editable
        name="testimonials"
        label=":"
        opt_values='lauras_testimonials.html'
        dynamic='opt_values'
        type='dropdown'
    />
</cms:repeatable>


…and here's the code where I want the ads to appear on the page:

Code: Select all
<cms:if k_is_page>
    <h1><cms:show k_page_title /></h1>
   
    <cms:show_repeatable 'lauras_testimonials_list' >
        <cms:if testimonials != '-' >
            <cms:pages masterpage='testimonials.php' id='testimonials' >
                <h3><cms:show k_page_title /></h3>
            </cms:pages>
        </cms:if>
    </cms:show_repeatable>
   
</cms:if>

…and here's the html file in the snippets folder:

Code: Select all
Please Select=-
<cms:pages masterpage='testimonials.php'>
   | <cms:show k_page_title  />=<cms:show k_page_id  />
</cms:pages>

The clonable template named 'testimonials.php' seems to be doing its job and creating a page for each testimonial and creating the drop downs for each row.

Can you see where it's gone wrong?
Any guidance will be fantastic.

Thanks
Hi pixelace,

I think the problem is that the template you are trying to show the ads on is non-clonable.
Which makes the <cms:if k_is_page> false and this would prevent the enclosed code from executing.

Please remove the <cms:if k_is_page> and the matching </cms:if> from the code and see if this helps.
18 posts Page 1 of 2