Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
17 posts Page 1 of 2
For my client, they run a business that conducts sales of household goods. For each sale we create a new page on their website. Each page has:

The Sale Date, Address of the Sale, Days that the sale is running, times that the sale is running, a headline, a sale description and a gallery of thumbnails (anywhere from 50-250 thumbnails) when the thumbnail is clicked, it brings up the image in lightbox and the user can go through all the pictures in this gallery.

I have created a template to do everything to create this clone able page and then display all of the information on the cloned page, except the gallery.

As I understand from the documentation and the forums, the user would then after creating this page from the template have to create a gallery in a separate template and do some manipulation of folders in order to tie all this together.

While I am fairly sure, I could pull that off, from a client/user standpoint, I think that is way over their head.

My proposal is to allow access to a image module from within another template, to allow multiple images to be uploaded all at once. This module would also rename all images and create a folder for those images specific to just that cloned page. This would automate the process and is what I'm sure a lot of folks hoped the Gallery Template would do.
Hi,

I think there already is something available in Couch that does just that.
Allow me to explain -

Assuming the main template is 'products.php' and each cloned product page requires a gallery of its own, please do the following -

Create a regular 'gallery' template (as explained at http://www.couchcms.com/docs/concepts/p ... llery.html). Let us call it 'gallery.php'.
Add the following editable region to it -
Code: Select all
<!-- in gallery.php -->

<cms:editable
    type='relation'
    name='photo_product'
    masterpage='products.php'
    has='one'
    no_gui='1'
    label='-'
/>

You'll recognize this as a normal 'many-to-one' relation where each photo in the gallery will be related to a single product.
The only new thing in the definition for you would be no_gui='1'. Normally when a many-to-one relation is configured, Couch displays a dropdown list showing the related pages ('products' in our example) to choose from. In our case, we'll set the related product programmatically (as opposed to choosing manually), so we simply turn off the GUI.

Perform the ritual 'visit as super-admin' step for the changes to persist.

Next, add the following editable region to 'products.php' -
Code: Select all
<!-- in products.php -->

<cms:editable
    type='reverse_relation'
    name='product_photos'
    masterpage='gallery.php'
    field='photo_product'
    anchor_text='View images'
    label='Gallery'
/>

This type='reverse_relation' would be new for you (not documented).
What it does is show a link to the 'gallery' associated with the product being edited (we'll see that in just a while).

Visit products.php as super-admin to persist the change.
Coming back to the admin-panel, create a new product cloned page and save it.
You should a link like this in the page -
Untitled-1.png
Untitled-1.png (7.05 KiB) Viewed 7266 times


IMP: the page needs to be saved before the link appears.

Clicking on the link will lead to the gallery edit page.
You'll notice that it clearly states that items are related to the product that we clicked to get here
Untitled-2.png
Untitled-2.png (7.32 KiB) Viewed 7266 times


Upload images as we normally do.
Untitled-3.png
Untitled-3.png (76.42 KiB) Viewed 7266 times


Couch will automatically relate the uploaded images to the indicated product.
Getting back to the product will now show the number of related images -
Untitled-4.png
Untitled-4.png (7.02 KiB) Viewed 7266 times


That takes care of the uploading images step.
It does entail switching over from one template to another but, I am sure, this won't be too difficult for your client.

To display the related images on the front-end, we use the normal cms:reverse_related_pages tag e.g.
placing the following code in 'products.php' will show all the galery images related to it
Code: Select all
<cms:if k_is_page >

    <h3>Gallery:</h3>
    <cms:reverse_related_pages 'photo_product' masterpage='gallery.php' >
        <!-- All variables of 'gallery.php' are available here -->
        <a href="<cms:show gg_image />"><img src="<cms:show gg_thumb />" /></a>
    </cms:reverse_related_pages>

</cms:if>

Hope this helps.
Do let us know.

Thanks.
KK,

Wow that is great stuff! I'm sure this will help others as well! One more question for you :)

Is there a way to make it so when a sale passes and the client deletes the sale (page), that the related gallery images can also be deleted without manually going into the gallery template and deleting them?

Also as a part 2, is there a way to make it so a sale (page and related images) delete automatically after the sale date?

Thanks as always, you are always so helpful!
Answer for both the questions is no, I am afraid.
Not possible out of the box.
@KK
Hi!
I'm taking this up, because there is some issue happening:

After having done most things by this mini-tutorial, I have 2 issues:

1. No_gui works only for input field (has type="hidden" in html), but the link is still visible. This one I have partially solved with label='&nbsp;' . However, semicolon ":" is still visible. I can deliver this to client without questions.

2. The gui is duplicated! Disabling one by no_gui='1' still leaves the other. I've used this technique to create a mini(nested)-gallery for each picture in a normal gallery (clonable, dynamic folders). It is like a photo product has different colors (also photos).
But this duplication of gui is somewhat unexpected.

I really need this fixed asap, what can be done here?
Thank you!

PS This nested gallery feature is a killer feature! Really nice.
But this duplication of gui is somewhat unexpected.
It is unexpected for me too.

I'll have to take a look at the issue first-hand to know the reason.
Wonder if you could grant me temporary FTP+Couch access to your site?
Uff.. While preparing everything had to reinstall couch and the problem is gone. :D :D :D
Thank you, KK, Couch is more stable than your humble follower trendoman.
That happens, Trendoman :)
I'm glad the problem is resolved.
Does anyone know how to display the items in a repeatable area?
@rayfcrols, sorry but I couldn't get your question -
if you choose to use repeatable-region (e.g. containing type 'image' region), then each cloned page will essentially have a 'nested' gallery of its own comprising of the images uploaded in the rows of the repeatable-region.

The original problem posted in this thread was about 'multiple images to be uploaded all at once'. This is where using the gallery addon comes in because using repeatable-region necessitates uploading images manually one-by-one.

Could you please elaborate a bit more on your question?
Thanks.
17 posts Page 1 of 2

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 1 guest