From GruppoZenit
Jump to: navigation, search

Z-CMS provides the following two Z-CMS tags to realize searching in websites: zcms:content-search and zcms:search-result.

Search to be performed on content data based on a search criterion has to be configured in Widgets using the Z-CMS search tag zcms:content-search. Search results can be presented using the zcms:search-result tag.

Example: implement search functionality in Z-CMS

Consider a webpage with a form containing a text box to input the search criterion and a link label to submit the form as illustrated below:

<form name="frm" id="frm" method="get" action="searchlist">
   <input type="text" name="txtsearch" id="txtsearch" value="" />
   <br />
   <a href="#javascript:document.frm.submit();">Search</a>

Clicking the link label "Search" will submit the form to another webpage named "searchlist".

It is required to create a Widget as illustrated below that can perform the search and then present the search result. Consider the name of the Widget as "search" and type as "list". The Widget in the following example performs the search on attribute content data of three Content Models: Exhibition_Names, Title_Description and Banner.

<zcms:content-search match="ANY_WORDS" parameters="txtsearch" datacount="10" id="search1" enablepage="true">
   <zcms:content name="Exhibition_Names">
      <zcms:datacolumn name="exhibition_name" alias="title"/>
      <zcms:datacolumn name="'EXB'" alias="identifier" />
      <zcms:filter attribute="publish" value="1"/>
      <zcms:filter attribute="exhibition_name" value="$search[txtsearch]" />
   <zcms:content name="Title_Description">
      <zcms:datacolumn name="title" alias="title" />
      <zcms:datacolumn name="description" alias="description" />
      <zcms:datacolumn name="'TD'" alias="identifier" />
      <zcms:filter attribute="publish" value="1" />
      <zcms:filter attribute="title" value="$search[txtsearch]" />
      <zcms:filter attribute="description" value="$search[txtsearch]" />
   <zcms:content name="Banner">
      <zcms:datacolumn name="Title" alias="title" />
      <zcms:datacolumn name="'BAN'" alias="identifier" />
      <zcms:filter attribute="publish" value="1" />
      <zcms:filter attribute="Title" value="$search[txtsearch]" />
            <zcms:attribute name="title" highlight="$search[txtsearch]" />
            <zcms:is attribute="identifier" operation="EQUALS" value="TD">
               <zcms:attribute name="description" highlight="$search[txtsearch]" />

Now, that the Widget is completed, it has to be included in "searchlist" page as follows:

<zcms:include widget="search" type="list" />

Note: in this example, the search criterion within the search result will be highlighted as well.

See also

Personal tools