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

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
johnboyuk1
Forum Members
Forum Members
Posts: 200
Joined: Mon Nov 26, 2018 3:09 pm

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

Post 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?
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm
Location: Nimbin, Australia

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

Post 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}
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1665
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

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

Post 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.
Not getting the answer you need? CMSMS support options
filto
New Member
New Member
Posts: 4
Joined: Fri May 06, 2022 1:40 am

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

Post 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
Last edited by filto on Fri May 06, 2022 2:48 am, edited 3 times in total.
johnboyuk1
Forum Members
Forum Members
Posts: 200
Joined: Mon Nov 26, 2018 3:09 pm

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

Post by johnboyuk1 »

Great - many thanks - I'll test these out!
Post Reply

Return to “CMSMS Core”