Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
61 posts Page 5 of 7
Previous 1, 2, 3, 4, 5, 6, 7 Next
Hi,
I have a question for file named 'search.htm (file in snippet folder)

I have routes views - each inserted file from the same snippet folder:
<cms:if k_matched_route='list_view'>
<cms:embed 'list_view_content.inc' />
<cms:else_if k_matched_route='custom_1' />
<cms:embed 'custom_1_content.inc' />
... ...
</cms:if>

Both files (list_view_content.inc & custom_1_content.inc ) contain filtering.
My question is:
Do I need a file named search.htm, or I can put the code from search.htm directly into the page list_view_content.inc & custom_1_content.inc?

Ask for assistance
Thanks
Hi @orbital,

Code within a snippet behaves *exactly* as it would if it was placed directly within templates.
So, both the methods should work. By using snippets you'd avoid duplication of code though.
Thanks for the reply KK ;)
I thought it must have an external file, because in the code (search.htm) has frm_ variables
I know that in such cases is mandatory code to be placed in another file
Can someone help me!

I am creating a website for with sofa. he is very good.

My client asked to create a filtered search.

the busa item search records within adminstrativo panel.

and research related to each item. example:

(Type) (trademark) (model).

exempo.

selection (type of) car. when you select (mark) display unique brand as the type. when you select (model). show only the models registered with the type.

I have a website of a competitor example.

http://www.caminhoesecarretas.com.br/Default.aspx

somebody help me ?

It is possible with the couch?

I'm from Brazil I have difficulty :cry:
Hi guys!
I'm facing the following situation. I have:
1. documents.php which is a clonable template;
2. document-reports.php which is a template with no editables defined, used only for filtering the documents via
3. document-report-filter.html snippet.
The filtering is made by year, document type, author, etc. In this filter I would like to use year from the publish date, as publish date is already available, but I don't know how.
It is possible to use it somehow directly in the search string
Code: Select all
<cms:if frm_years!='-' >
            <cms:set my_search_str="<cms:concat my_search_str ' | docyear==' frm_years />"  scope='global'/>
         </cms:if>
, or year most be saved in documents.php template docyear editable previously to use it in the search string?
Any help is appreciated.

Attila
I would say, start_on & stop_before parameters can help here. Basically, start_on='2016-01-01' stop_before='2017-01-01'. But sometimes the years of the cloned pages vary and not known beforehand. In this case, please study <cms:archives /> tag, since it can get you a list of available years.
Thanks Trendoman for your suggestion.
However, I really would like to use the year from publish date somehow in a simpler manner if is possible. I forgot to mention the fact that when adding new documents from the front-end, I'm using KK's solution listed here http://www.couchcms.com/forum/viewtopic.php?f=4&t=8836&p=25585&hilit=edit+date+from+databound#p25585 , so the publish date is available, as user must input it from the front-end.
Code: Select all
<cms:db_persist_form
                    _invalidate_cache='0'
                    _auto_title='1'
                    k_publish_date=frm_my_datetime
                    author=my_name
          memberid=my_memberid
                    idfolder=my_page_id
                />
So I just have to grab the year part of frm_my_datetime somehow, and save it in an editable created for this in my documents.php template.
Am I right?
@atisz, please post your code (both showing years in filter and custom listing) so I could get you some easy code for years.

The solution with saving user-inputted year to editable is somewhat cumbersome, requires extra efforts which are not always reliable. It would be a big load for the server to fetch all cloned pages and find unique year from each of the page. Such tasks are managed by database 1000x faster. We should use proper tools :)
@trendoman
This is what I've done so far:
1. document-reports.php
Code: Select all
<div><!-- Start search snippet -->
   <cms:embed 'document-report-filter.html' />
</div><!-- End search snippet -->

<div id="navigation-bar">
   ......
</div>

<div id="table"><!-- Start table -->
   <table>
       <tr>
         <th>Date</th>
         <th>Document name</th>
         <th>Document type</th>
            <th>Author</th>
       </tr>                           
      <cms:pages masterpage='members/documents.php' custom_field=my_search_str order='asc' paginate='1' limit='20'>
         <cms:if k_paginated_top >
               <cms:set my_records_found='1' scope='global'/>
               <cms:if k_paginator_required >
                     Page <cms:show k_current_page /> of <cms:show k_total_pages /><br />
               </cms:if>
           
            </cms:if>
         <cms:if excludreg >
               ... do something ....                        
         <cms:else />
                <tr>
               <td><cms:date k_page_date format='d.m.Y' /></td>
               <td><cms:show docname /></td>
               <td><cms:show doctype /></td>
                    <td><cms:show author /></td>
             </tr>
            </cms:if>                  
      </cms:pages>
   </table>   
</div><!-- End table -->

2. document-report-filter.html
Code: Select all
   <cms:form name="quicksearch" id="quicksearch" anchor='0'>
      <cms:if k_success >
         
         <cms:if frm_years!='-' >
            <cms:set my_search_str="<cms:concat my_search_str ' | docyear==' frm_years />"  scope='global'/>
         </cms:if>
         
         <cms:if frm_doctypes!='-' >
            <cms:set my_search_str="<cms:concat my_search_str ' | doctype==' frm_doctypes />"  scope='global'/>
         </cms:if>
           
            <cms:if frm_authors!='-' >
            <cms:set my_search_str="<cms:concat my_search_str ' | author==' frm_authors />"  scope='global'/>
         </cms:if>
         
      </cms:if>
      
      <div>
         <label>Year:</label><br />
         <cms:input type="dropdown"
               opt_values="All=- | <cms:pages masterpage='members/years.php' order='asc'><cms:show year /><cms:if k_paginated_bottom='0' >|</cms:if></cms:pages>"
               opt_selected='All'
               name="years" id="years" />
      </div>
      <div>
         <label>Document type:</label><br />
         <cms:input type="dropdown"
                  opt_values="All=- | Internal | Incoming | Outgoing"
               opt_selected='All'
               name="doctypes" id="doctypes" />
      </div>
        <div>
         <label>Author:</label><br />
         <cms:input type="dropdown"
               opt_values="All=- | <cms:pages masterpage='members/index.php' order='asc'><cms:show k_page_title /><cms:if k_paginated_bottom='0' >|</cms:if></cms:pages>"
               opt_selected='All'
               name="authors" id="authors" />
      </div>
         <br />
      <div class="buttonset">
         <cms:input type="submit" class="fbsubmitbtn" value="Generate report" name="submit"/>
      </div>
   </cms:form>

Currently the year filter is working using the docyear field from documents.php, which is populated automatically with the year on form submition (add-document.php), but unfortunately the use case is a little special, from this reason the field is populated sometimes with the wrong year. That's why I was thinking to use year from publish date, because this is what matters and it is always correct, even if user edits it :)
Thanks!

Attila
I guess, we should create the filter with years correctly.
So let's check template 'members/documents.php' and get all distinct years consecutively from its pages (via publish date).

I know that there is this tag - <cms:archives />, which shows time period (year, month, day) and displays number of pages in each period.
Obviously, if there are no pages in period, then it is skipped. It can be tried out with following code:
Code: Select all
<cms:archives masterpage='members/documents.php' type='monthly' >
    <cms:dump />
</cms:archives>

It displays something like that (note, how k_archive_count shows number of pages in the month starting with k_archive_date and ending before k_next_archive_date).

archives
k_archive_date: 2016-10-01
k_next_archive_date: 2016-11-01
k_archive_link: http://www.site.com/index.php?d=201610
k_archive_count: 10
k_count: 1

archives
k_archive_date: 2016-09-01
k_next_archive_date: 2016-10-01
k_archive_link: http://www.site.com/index.php?d=201609
k_archive_count: 90
k_count: 2

archives
k_archive_date: 2016-07-01
k_next_archive_date: 2016-08-01
k_archive_link: http://www.site.com/index.php?d=201607
k_archive_count: 9
k_count: 3


Once we understand how tag works, let's make it 'yearly' for our purpose.
Output would be similar to following:
archives
k_archive_date: 2016-01-01
k_next_archive_date: 2017-01-01
k_archive_link: http://www.site.com/index.php?d=2016
k_archive_count: 109
k_count: 1

archives
k_archive_date: 2015-01-01
k_next_archive_date: 2016-01-01
k_archive_link: http://www.site.com/index.php?d=2015
k_archive_count: 23
k_count: 2


This way we can see the years of our pages by k_archive_date. Format is 'Y-m-d', and to get only year it's necessary to convert it with 'Y' format, using <cms:date /> tag -
Code: Select all
<cms:date date=k_archive_date format='Y' />


What we want to achieve - submitted form should send to backend 2 dates - starting date and ending date. We have both, so let's assign a special value to each year - like year = start date # stop date, sample: 2016 = 2016-01-01 # 2017-01-01.
So, frm_year will have 2 dates and we can split it to feed our listing.

k_success block in the form would split it:
Code: Select all
         
<cms:if frm_years!='-' >
    <cms:each var=frm_years sep='#' >
       <cms:if k_count='0' ><cms:set start_date = item scope='global' />
       <cms:else_if k_count='1' /><cms:set end_date = item scope='global'  />
       </cms:if>
    </cms:each>
</cms:if>


Now, listing will be changed very slightly:
<cms:pages masterpage='members/documents.php' custom_field=my_search_str order='asc' paginate='1' limit='20' start_on=start_date stop_before=end_date >


If year is not selected and variables start_date / end_date do not exist, listing will ignore empty values and show without year constraint.

So, finally, modify your input dropdown for years. It was like this:
Code: Select all
      <div>
         <label>Year:</label><br />
         <cms:input type="dropdown"
               opt_values="All=- | <cms:pages masterpage='members/years.php' order='asc'><cms:show year /><cms:if k_paginated_bottom='0' >|</cms:if></cms:pages>"
               opt_selected='All'
               name="years" id="years" />
      </div>     

And we can change it to display only existing years, as planned.
Code: Select all
     
      <div>
         <label>Year:</label><br />
         <cms:input type="dropdown"
               opt_values="All=- | <cms:archives masterpage='members/documents.php' type='yearly' ><cms:date date=k_archive_date format='Y' /> = <cms:concat k_archive_date ' # ' k_next_archive_date />|</cms:archives>"
               opt_selected='-'
               name="years" id="years" />
      </div>     
     



Ask any questions.

:)
Previous 1, 2, 3, 4, 5, 6, 7 Next
61 posts Page 5 of 7