• 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.  [ 10 posts ] 
Author Message
 Post subject: Search - results template - add content?
PostPosted: Sat May 07, 2011 10:27 pm 
Offline
Forum Members
Forum Members

Joined: Tue Aug 19, 2008 6:30 pm
Posts: 93
Location: NY
I'm trying to add a few lines of content to the search results template. I wonder if anyone knows of an easy solution to do this?

I've tried adding "$entry->content" to the template, like this, but it doesn't seem to work:
Code:
{foreach from=$results item=entry}
  <li>{$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a> ({$entry->weight}%)<br />{$entry->content|truncate:300}</li>
{/foreach}


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Search - results template - add content?
PostPosted: Sat Jun 18, 2011 9:24 pm 
Offline
Forum Members
Forum Members

Joined: Mon Jul 13, 2009 8:18 pm
Posts: 146
Don't know if you are still looking for an answer for your question but I can help you a bit.

I'm looking into how the search works right now and this is what i found:

Let's say you want some more text from the news module. Make a new detail template in the news module (call it search or whatever) and only add the fields you want your search page to show:
Code:
{$entry->postdate|cms_date_format}{$entry->title|cms_escape:htmlall}


You can add any detail field you want that would normally be available in detail view.

Now in the search module template edit it so that when it stumbles on news results it will display the result with your news template:

Code:
 {if $entry->module == 'News'}
          <a href="{$entry->url}">
          {News action='detail' articleid=$entry->modulerecord detailpage='News' detailtemplate="search" }
          </a>
{elseif}
rest of your search code


Hope it helps..!


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Search - results template - add content?
PostPosted: Sun Jun 19, 2011 9:57 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Aug 12, 2008 9:30 pm
Posts: 2071
Location: Feldkirchen in Kärnten, Austria
Just recently i needed to show small chunck of content text for search results so for content pages you can do a combo of UDT, CGSimpleSmarty.

As Search module gives only Title of the page, or i at least didn't find a way to get page alias from it i was in need of a UDT:

Call it set_alias
Code:
/** Get page alias from title
* @params string $params['title']
*/
$gCms = cmsms();
$cntnt = cmsms()->GetContentOperations();

foreach ($cntnt->GetAllContent() as $page) {
 if ($page->mName == $params['title']) {
   $return = ($page->mAlias);
   break;
 }
}
if(!empty($params['assign'])){
        $smarty = cmsms()->GetSmarty();
        $smarty->assign(trim($params['assign']), $return);
}
else{
        return $return;
}


Now you can build your search result template with this UDT and CGSimpleSmarty (note that i didn't use any module search here, so if you need that to add it as suggested above).
Code:
<h3>{$searchresultsfor} &quot;{$phrase}&quot;</h3>
{if $itemcount > 0}
<ul>
  {foreach from=$results item=entry}
  {set_alias title=$entry->title assign='get_alias'} {* call set_alias udt and assign as get_alias *}
  <li>{$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a> ({$entry->weight}%)<br />
   {$cgsimple->get_page_content($get_alias,'content_en','result_content')}{$result_content|truncate:'160'|strip_tags} {* cgsimplesmarty looks through our var get_alias and content and assigns var result_content, then we output found content with result_content and truncate it to desired number of character *}
</li>
  {/foreach}
</ul>

<p>{$timetaken}: {$timetook}</p>
{else}
  <p><strong>{$noresultsfound}</strong></p>
{/if}

_________________
CMSMS Blog - I do this!
Forge profile
Github profile
Twitter
=============================================
Support CMSMS


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Search - results template - add content?
PostPosted: Wed Jul 13, 2011 11:46 pm 
Offline
Forum Members
Forum Members

Joined: Thu Oct 26, 2006 9:20 am
Posts: 137
Location: Dresden - Saxony - Germany
wow uniqu3 - uve just made my day :)

Is it possible to get the the news module output too within your solution?


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Search - results template - add content?
PostPosted: Thu Jul 14, 2011 9:17 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Aug 12, 2008 9:30 pm
Posts: 2071
Location: Feldkirchen in Kärnten, Austria
Well probably it would work if you combine it with vinyl's solution.

_________________
CMSMS Blog - I do this!
Forge profile
Github profile
Twitter
=============================================
Support CMSMS


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Search - results template - add content?
PostPosted: Thu Jul 14, 2011 11:27 am 
Offline
Forum Members
Forum Members

Joined: Thu Oct 26, 2006 9:20 am
Posts: 137
Location: Dresden - Saxony - Germany
works fine. You just need to insert {if $param_module != 'News'} within the foreach because your solution also displays the title of the news module.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Search - results template - add content?
PostPosted: Mon Nov 21, 2011 5:41 pm 
Offline
Forum Members
Forum Members

Joined: Wed Sep 28, 2011 1:22 am
Posts: 29
When I try your solution it gives me the following error...

Code:
Fatal error: Cannot access protected property Content::$mAlias in /var/websites/test.com/lib/classes/class.usertagoperations.inc.php(260) : eval()'d code on line 9


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Search - results template - add content?
PostPosted: Mon Nov 21, 2011 10:36 pm 
Offline
Power Poster
Power Poster

Joined: Mon Sep 08, 2008 9:43 am
Posts: 307
andy4oo wrote:
Hey guys i using babel multi language site, is there a way to show the results by language? I meant to show them for each language so the guy from english cant see the spanish or oter lang pages. Thanks


I did it this way:
I have different news categories for each language and named them de_DE and en_US and so on...

In Babel's language menu I assign the current language to a variable $currentlang:(later used in news template)
Code:
{if $language->is_current}{assign var=currentlang value=$language->name}

I have a news detailtemplate called searchresult in which I compare $currentlang to news-category:
Code:
{if $currentlang eq 'en' && $entry->category eq "en_US"}
...result...
{elseif $currentlang eq 'de' && $entry->category eq "de_DE"}
...result...

This way I filter out the language results not applicable to the current language.

Finally in the SEARCH resulttemplate:
Code:
{cms_module module='News' action='detail' articleid=$entry->modulerecord detailtemplate='searchresult'}


Works fine!


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Search - results template - add content?
PostPosted: Tue Nov 22, 2011 7:41 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Aug 12, 2008 9:30 pm
Posts: 2071
Location: Feldkirchen in Kärnten, Austria
@slabbe

This works with 1.10.x, it's slightly different then above UDT, as instead of comparing results against title i compare it with url, title wasn't realy good way as it isn't unique.

Code:
/** Get page alias from url
* @params string $params['url']
*/
$gCms = cmsms();
$cntnt = cmsms()->GetContentOperations();

foreach ($cntnt->GetAllContent() as $page) {
if ($page->GetURL() == $params['url']) {
   $return = $page->Alias();
   break;
}
}
if(!empty($params['assign'])){
        $smarty = cmsms()->GetSmarty();
        $smarty->assign(trim($params['assign']), $return);
}
else{
        return $return;
}


@andy4oo
To return only results for current language i did something like that (note using CGSimpleSmarty):
Code:
  {foreach from=$results item=entry}
   {get_alias url=$entry->url assign='set_alias'} {* above UDT *}
   {$cgsimple->get_root_alias($set_alias, 'is_lang')}

    {if $is_lang == $lang_parent}{* compare root_alias to mle var *}
      <a href="{$entry->url}">{$entry->urltxt}</a>
      <span class="result-content">
         {$cgsimple->get_page_content($set_alias,'content_en','result_content')}
            {$result_content|truncate:'100'|strip_tags}
      </span>
// AND SO ON...
    {/if}
  {/foreach}

_________________
CMSMS Blog - I do this!
Forge profile
Github profile
Twitter
=============================================
Support CMSMS


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Search - results template - add content?
PostPosted: Mon Mar 18, 2013 12:34 am 
Offline
Forum Members
Forum Members

Joined: Sun Dec 16, 2012 11:41 pm
Posts: 28
Hi. I've put the above code by uniqu3 in CMS Made Simple 1.11.4, but doesn't work. Could you tell me if it has to be modified for 1.11.4 and eventually could you post the updated UDT and Results Template code?
Thanks


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.  [ 10 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:  
cron
A2 Hosting