• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Search results from News by category using only templates
PostPosted: Fri Jul 13, 2012 4:49 am 
Offline
Power Poster
Power Poster

Joined: Sat Jan 22, 2005 11:19 am
Posts: 463
It seems that the passthru parameter when using the Search module to search other modules is not yet implemented. Until it is, you may want to try the following. It works for me.

The module I'm searching is News and I only want to find articles in the 'faq' or 'faq' child categories.

In the News module, create the following summary template. I've named it 'searchnewsfaqsummary':
\$1:
{if $items|count gt 0}
{assign var=newsids value='~'}
{foreach from=$items item=item}
{$newsids|cat:$item->id|cat:'~'}
{/foreach}
{/if}


In Search, modify the results template as follows:
\$1:
{strip}
<h3>{$searchresultsfor} &quot;{$phrase}&quot;</h3>
{if $itemcount > 0}
   {capture assign=newsids}
      {cms_module module=News category="faq*" summarytemplate='searchnewsfaqsummary'}
   {/capture}
   
   {foreach from=$results item=entry}
      {assign var=modrecord value='~'|cat:$entry->modulerecord|cat:'~'}
      {if $entry->module == 'News' and $newsids|strpos:$modrecord !== false}
         <p><a href="{$entry->url}">{$entry->urltxt}</a> ({$entry->weight}%)</p>
      {/if}
   {/foreach}
{else}
   <p><strong>{$noresultsfound} Try again</strong></p>
   {cms_module module=Search modules='News' search_method="post"}
{/if}
{/strip}


It works as follows:
- The Search module only makes one call to the News module so overhead is minimal.
- The news summary template creates a string something like ~12~ ~22~ ~37~
- The Search results template creates a variable {$modrecord} to which is prepended and appended a tilde ~ character to ensure each modrecord id string is unique
- The Search template then iterates through the $result list and compares the $modrecord (with ~ on both ends) to see if the same string appears in the captured News output.
- When a match is found, it outputs the Search result link

Please Note:
1. I changed the News template from the default {foreach from=$items item=entry} to {foreach from=$items item=item} to ensure it doesn't get confused with the Search $entry var.
2. While you can only have one Search result template, you can search and output results from multiple modules by refining the {if}{elseif}{else} statements to suit (and maybe adding eg 'and $page_alias eq 'faq'} or similar to narrow down the result set to get the correct results for a particular page.

It's not perfect but should get you by until the Search module passthru parameter is implemented.

Hope this helps
psy


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Search results from News by category using only template
PostPosted: Mon Nov 12, 2012 11:17 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Oct 05, 2006 10:58 pm
Posts: 51
Location: Alkmaar
This works great for me!

I use it in combination with my custom search.
\$1:
<span class="resulttext">{$searchresultsfor} &quot;{$phrase}...&quot;</span>

{if $itemcount > 0}
   {capture assign=newsids}
               {if ($page_language=="en")}
               {cms_module module=News category="English*" summarytemplate='searchnewsfaqsummary'}
            {elseif ($page_language=="nl")}
               {cms_module module=News category="Nederlands*" summarytemplate='searchnewsfaqsummary'}
            {/if}
   {/capture}
   {counter assign=idx print=0}
   {foreach from=$results item=entry}
      {if $idx <= 6}
         {assign var=modrecord value='~'|cat:$entry->modulerecord|cat:'~'}
         {assign var="url_lang" value="/"|explode:$entry->url}
         {if (($url_lang[3]=="en") || ($url_lang[3]=="fr") || ($url_lang[3]=="nl") || ($url_lang[4]=="en") || ($url_lang[4]=="fr") ||       ($url_lang[4]=="nl"))}
            {if ($url_lang[3]==$page_language) || ($url_lang[4]==$page_language)}
               <a href="{$entry->url}">
                  <div class="searchitem"><h3>{truncate_better text=$entry->title truncate='29' add='...' }</h3>
                     {truncate_better text=$entry->urltxt truncate='90' add='...' }
                  </div>
               </a>
               <hr/>
               {counter}
            {/if}
         {elseif $entry->module == 'News' and $newsids|strpos:$modrecord !== false}
            {if ($page_language=="en")}
               {news action='detail' articleid=$entry->modulerecord detailpage='news' detailtemplate="CLBNewsSearch"}
               {counter}
            {elseif ($page_language=="nl")}
               {news action='detail' articleid=$entry->modulerecord detailpage='nieuws' detailtemplate="CLBNewsSearch"}
               {counter}
            {/if}
         {/if}         
      {/if}
   {/foreach}

{else}
  <p class="noresult">{$noresultsfound}</p>
{/if}


See: http://www.soundintel.com/ for a working solution!


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting