Page 1 of 1
Question about the search module
Posted: Thu Nov 22, 2012 9:04 pm
by gdur
Search does offer the ability to limit the search results to a specified module which is nice. Now I'm looking for the opposite. Is there a way to exclude a certain or a list of modules to be excluded from the search results?
Re: Question about the search module
Posted: Mon Nov 26, 2012 3:07 pm
by scooper
It's cheating slightly but you can check in the search results template which module is producing the search result and then chose whether to display it or not.
Code: Select all
{if $entry->module ne 'YourSecretModule'}
{$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a>
{/if}
There's actually an example in the default search results template now I come to look.
Re: Question about the search module
Posted: Mon Nov 26, 2012 4:05 pm
by gdur
Thanks for the response. Sadly it doesn't really answers the question. The example you are referring to works for the news module. I actually want to limit search to the "content" table (thus the regular pages) but don't know how to call that because it isn't a module is it?
Re: Question about the search module
Posted: Mon Nov 26, 2012 4:37 pm
by scooper
What the above code does is hide results from 'YourSecretModule'.
So for any modules that you want not to appear in the results you just add them to the conditional.
For example
Code: Select all
{if $entry->module ne 'News' && $entry->module ne 'CGBlog'}
{$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a>
{/if}
will not show results from the News or Blog modules. The 'ne' in the smarty tag is 'not equal' so only results that aren't News or Blog get displayed
If you're sure you want to hide results from all modules and only show results from content then you can check to see if the value for module is empty:
Code: Select all
{if $entry->module == ''}
{$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a>
{/if}