Forum for discussing general topics related to Couch.
4 posts Page 1 of 1
Tried to make relation between various products gallery (folders) and various blog posts. Following tutorial, this code below is not acceptable for me and i don`t need new uploader because my images already exists in product galleries.

<!-- in products.php -->
Code: Select all
 <cms:editable  type='relation' name='photo_product'  masterpage='blog.php'  has='one'  no_gui='1'  label='-' />


<!-- in blog.php -->
Code: Select all
<cms:editable  type='reverse_relation'  name='product_photos' masterpage='products.php'  field='photo_product' anchor_text='View images' label='Gallery'  />


So, this 'direct' relation is not good in my case.

I need to make these steps to simplify whole process:
- create new blog post
- choose some product gallery from dropdown menu
- first image (from choosed product gallery) is leading post photo / with lightbox
- other gallery images in blog post are bellow post content / / with lightbox

I created

My product.php

Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Products' clonable='1' dynamic_folders='1' gallery='1' folder_masterpage='products-folders.php' order='3'>
    <cms:editable name='grid_image_desc' assoc_field='gg_image' label='Additional description' desc='Whown in product category' width='480' height='302' type='richtext' order='1'/>
   <cms:editable name='gg_image' label='Image' desc='Upload your main image here' width='480' show_preview='1' preview_height='200' type='image' order='2'/>
   <cms:editable name='gg_thumb' assoc_field='gg_image' label='CMS Thumbnail Image' desc='Only used within the admin panel' width='115' height='115' enforce_max='1' type='thumbnail' order='3'/>
   <cms:editable name='grid_thumb' assoc_field='gg_image' label='Grid Thumbnail Image' desc='Used on the front end' width='480' height='302' crop='1' type='thumbnail' order='4'/>
</cms:template>

<cms:if k_is_page >

<?php include('header.php'); ?>

<body>
<cms:folders>
<a href="<cms:show k_folder_link />"><cms:show k_folder_title /></a>
   <cms:show k_folder_image />
</cms:folders>   

<?php include('footer.php'); ?>

<cms:else />
      <cms:embed 'products.html' />
</cms:if>

<?php COUCH::invoke(); ?>


My products-folders.php
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Product folders' clonable='1' hidden='1' order='3'>
<cms:editable name='form_msg' type='message' order='5'>
<hr>
<b>FORM</b><br />Lorem ipsum...
</cms:editable>
   <cms:repeatable name='form' label='Form' order='5'>
        <cms:editable name='title' label='Name' type='text'/>
        <cms:editable name='type' type='dropdown' label='Type' opt_values='Text=text | Text Area=textarea | Radio Buttons=radio | Checkbox=checkbox | Dropdown=dropdown | Date=datetime | E-mail=email'/>
        <cms:editable name='options' label='Options' type='text' />
        <cms:editable name='required' label='Mandatory?' type='radio' opt_values='Yes=1| No=0' />
        <cms:editable name='text' label='Error msg' type='text' />
    </cms:repeatable>
</cms:template>

<?php COUCH::invoke(); ?>


My blog.php
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<?php include('header.php'); ?>
<cms:template title='Blog' clonable='1' order='6'>
   <cms:editable name='post_content' label='Post content' type='richtext' />
   <cms:editable name=post_image' label='Post image' crop='1' type='image' />
   <cms:folder name="news" title="News" />
        <cms:folder name="news" title="Product offer" />
        <cms:folder name="news" title="Category 3" />
        <cms:folder name="news" title="Category 4" />
</cms:template>

<cms:if k_is_page >
<body>
   <div class="row">
        <div class="box">
         <div id="breadcrumbs">
            <strong>Page:</strong> <cms:breadcrumbs separator='&nbsp;&raquo;&nbsp;' include_template='1'/><cms:if k_is_page >&nbsp;&raquo;&nbsp;<cms:show k_page_title /></cms:if>
         </div>
         <div class="col-lg-12">
               <div class="row">
               <div class="col-lg-12">
               <hr>
               <h2 class="intro-text text-center">
               <cms:show k_page_title />
                  <cms:if k_page_foldertitle >
                     <cms:set my_category=k_page_foldertitle />
                  <cms:else />
                     <cms:set my_category='Uncategorised' />
                  </cms:if>
               <span>Category: <cms:show my_category /> | Publish date: <cms:date k_page_date format='jS M, y'/></span></h2>
               <hr>
            
               </div>
            </div>   
         </div>
         <div class="row">
                <div class="col-lg-3">
               <cms:embed 'blog_sidebar.html' />
            </div>
            <div class="col-lg-9">
               <div id="posts">
                  <div class="col-md-4 text-left ">
                     <img class="img-responsive" src="<cms:show post_image />" alt=""/>
                  </div>
      
                  <div class="col-md-8 text-left blog-item">
                     <cms:show post_content />
                     <a href="<cms:link masterpage='blog.php' />" class="btn btn-default" >&lt;&lt; Show all blog items</a>
                     
                     
                     
                  </div>
               </div>
                </div>
            </div>
        </div>
    </div>
<?php include('footer.php'); ?>

<cms:else />
   <cms:embed 'blog_list.html' />
</cms:if>

<?php COUCH::invoke(); ?>
Hi,
- create new blog post
- choose some product gallery from dropdown menu
Basically if the blog template could be related to the folders of product template, you'd see the kind of dropdown you mentioned while creating a blog (i.e. showing list of product folders).

Unfortunately, relations work only between pages to pages and not folders.
But don't worry :) We can use a different tack to get something similar.

We'll use a regular dropdown editable region in blog.php and dynamically populate it with folders of product.php. This way the user can explicitly connect a blog post to one particular product folder.

Perhaps you'd like to see the following topic that discusses dynamically populating a dropdown
viewtopic.php?f=4&t=1671&p=2483&hilit=dynamic+params#p2483

In our case, define the following editable region in blog.php
Code: Select all
<cms:editable 
    name="my_related_folder"
    label="Related folder"
    opt_values='my_folder_listing.htm'
    dynamic='opt_values'
    type='dropdown'
/>

Place a file named 'my_folder_listing.htm' within the snippet folder (default is 'couch/snippets') and put the following in it
Code: Select all
Please Select=-
<cms:folders masterpage='product.php'>
    | <cms:show k_folder_title  /> = <cms:show k_folder_name />
</cms:folders>

Refresh blog.php as super-admin fpr the changes to persist.
Now when you create/edit a blog post, you should see a dropdown displaying all product.php folders to choose one from.

OK, so that part 1 of the solution.
Part 2 would be to use the folder selected above to display the images within it.

This is regular stuff.
If you do a <cms:show my_related_folder /> you'll see the name of the selected folder (or a '-' if none selected).
Combine that with the fact that the cms:pages tag accepts a 'folder' parameter to constrain its listing to only that folder and we have our solution.

For example, placing the following in blog.php's page-view should fetch all product pages in the related folder -
Code: Select all
<cms:if my_related_folder != '-' >
    <cms:pages masterpage='product.php' folder=my_related_folder>
        <!-- all pages (i.e. images) from the folder available here -->
    </cms:pages>
</cms:if>

Please note that in the code above we first check if a folder has indeed been selected before doing the listing.

I'm sure you can tweak the code above to create the kind of slideshow you mentioned.

Hope this helps.
Sure it helps Kamran :)

All this flexibility make sense for all my further projects.. Cloned pages - relation, folders and all can work absolutely fantastic without any fault.

The only thing that bother me is true multilingual support and flexibility of translation on the fly such as other cms have. I am waiting for Couch to become true operable multilingual cms. Some times I need cms that easily holds lot of different type of contents on 5 or 6 different languages for robust site.

Anyway I like flexibility of Couch and I respect your effort to make it even better.
Thank you!
I am glad it helped, proteus :)

Thank you very much for the kind words.
I agree with your observation about true multi-lingual functionality. There is so much more that Couch has yet to cover. I am sure we'll cover multi-lingual as we move ahead.

Thanks for your support.
4 posts Page 1 of 1