Forum for discussing general topics related to Couch.
5 posts Page 1 of 1
Hello,

I've set up a clonable template for Events. For handling events from different years I'm using folders. What I want to know if it's possible and how is possible to do some filtering in list view based on a dropdown containing the created folders name. I can manage listing all the events, but I don't know how to set up the dropdown and filter the listed events to show only the events belonging to the selected year.

Attila
Have you considered using the page dates instead of folders for this?

To the question in hand... The following code would generate the markup for your dropdown and populate it with the folder data. When someone chooses one of the select options, they will be redirected to the relevant folder view URL.
Code: Select all
<cms:set current_folder_name = k_folder_name/>

<form method="get" action="">
   <select name="date" onchange="if (this.options[this.options.selectedIndex].getAttribute('data-url') != '#') window.location.href = this.options[this.options.selectedIndex].getAttribute('data-url');">
      <option data-url="#" value="">-- Choose Year --</option>
      <cms:folders masterpage='events.php'>
         <cms:if k_folder_pagecount>
            <option data-url="<cms:show k_folder_link/>" value="<cms:show k_folder_name/>"<cms:if k_folder_name == current_folder_name> selected="true"</cms:if>><cms:show k_folder_title/></option>
         </cms:if>
      </cms:folders>
   </select>
   <noscript>
      <input type="submit" value="Filter">
   </noscript>
</form>


In the pages tag we then use the k_folder_name variable for the folder parameter which is set when in the folder view.
Code: Select all
<cms:pages masterpage='events.php' folder=k_folder_name>

   ...

</cms:pages>


One thing to note, we haven't yet accounted for JS-disabled visitors. Place the following code at the top of your page:
Code: Select all
<cms:if "<cms:gpc 'date' method='get'/>">
   <cms:redirect url="<cms:link masterpage='events.php' folder="<cms:gpc 'date' method='get'/>"/>"/>
</cms:if>
Thank you cheesypoof for your reply! In fact, yes, it crossed my mind that maybe it's better to use date instead folders.
I'll give it a try, and I will post a reply after implementing your solution.

Attila
Atisz please look at my revised post as I had a moment of insanity :oops: and overlooked Couch's folder view which we can use in this situation.
Thanks cheesypoof for helping me out. It's working perfectly, just the way I wanted!

Attila
5 posts Page 1 of 1