Page 1 of 1

Help with News module and Search - displaying results in correct template

Posted: Thu May 05, 2022 3:08 pm
by johnboyuk1
Hi

I've got a problem with the Search module and the way it works with the News module.. hoping someone can help.

If I perform a search with the search module, and click on a result that was found in a news article, the page it takes you to doesnt use the 'Detail' page I have set from within the News modules options... instead it loads the news article into the content area of the search results.

If I go to the Search extensions options there is a setting 'Page for individual module results' where if I select the News detail page it will work as expected... but then this will obviously cause problems with results from other modules!

I hope that all made sense! Is there a way to get the intended behaviour? Where news results will open in the News Detail page?

Re: Help with News module and Search - displaying results in correct template

Posted: Thu May 05, 2022 6:20 pm
by rotezecke
I'm not sure I understand the problem but this is a snippet i kept from an old sample search result template (i never used it this way though):

Code: Select all

{if $entry->module == 'News'}{News action='detail' article_id=$entry->modulerecord detailpage='News'} {/if}

Re: Help with News module and Search - displaying results in correct template

Posted: Thu May 05, 2022 11:14 pm
by DIGI3
I was looking for a workaround for this recently too, the Search module doesn't honour the News detailpage in the results. I ended up hardcoding the detailpage in the search results template like this:

Code: Select all

    {if $entry->module == 'News'}
      <li>{$entry->title} - <a href="{root_url}/news/{$entry->modulerecord}/54/{$entry->urltext}">{$entry->urltxt}</a> ({$entry->weight}%)</li>
    {else} etc.
Where '54' is the ID of the page I want the detail results displayed in.

Re: Help with News module and Search - displaying results in correct template

Posted: Fri May 06, 2022 2:03 am
by filto
1 --- in the search results template :

Code: Select all

 {if $entry->module == 'News'}
   
   {* --- use this if NOT url_rewriting --- *}
      {*
         <li>{$entry->title} - <a href="{$entry->url|replace:"returnid=$page_id":"returnid=$news_page_id"}">{$entry->urltxt}</a> ({$entry->weight}%)</li>     
       *}
       
   {* --- use this if active url_rewriting --- *}
      {assign var=article_id value=$entry->modulerecord}
       <li>{$entry->title} - <a href="{$entry->url|replace:"$article_id/$page_id":"$article_id/$news_page_id"}">{$entry->urltxt}</a> ({$entry->weight}%)</li>

{else}
    <li>{$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a> ({$entry->weight}%)</li>   
 {/if}
2 --- in your search result page : in tab Logic add into Smarty data : define id of your news detail page

Code: Select all

{$news_page_id='9' scope=root}  
Then if you change your news detail page, you just have to modify id defined in your search result page, and it allow others admin to manage it without having access to search result template

Re: Help with News module and Search - displaying results in correct template

Posted: Fri May 06, 2022 10:06 am
by johnboyuk1
Great - many thanks - I'll test these out!