• 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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Adding {$entry->content} to search results.
PostPosted: Wed Sep 05, 2018 2:36 pm 
Offline
Forum Members
Forum Members

Joined: Wed Aug 08, 2018 4:59 pm
Posts: 55
Im trying to add {$entry->content} to the search results of my page but with out any luck.


\$1:
 <li><a href="{$entry->url}">{$entry->urltxt}</a> ({$entry->weight}%)
     
</li>
{$entry->content}


I know there is a 7 years old post here about the the same issue.
The solution presented in that post doesn't seems to be working with cms 2.x....

Can someone experienced explain to me if it it is possible or not?

thanks in advance.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Wed Sep 05, 2018 2:45 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Feb 25, 2009 4:25 am
Posts: 850
Location: Victoria, BC
You could add <pre>{$entry|print_r}</pre> to see what options are available.

If content isn't one of them, you might be able to do something with {page_attr} to obtain the content.

_________________
Not getting the answer you need? CMSMS support options


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Wed Sep 05, 2018 2:54 pm 
Offline
Forum Members
Forum Members

Joined: Wed Aug 08, 2018 4:59 pm
Posts: 55
I tried <pre>{$entry|print_r}</pre> content is not one of the options.

I'm to much of a newbie to know how to play with the {page_attr} tag :)


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Wed Sep 05, 2018 3:16 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Feb 25, 2009 4:25 am
Posts: 850
Location: Victoria, BC
I just did a bit of testing, and it doesn't look like it's going to be possible to reliably get the page alias from the $entry array.

You could use javascript/ajax to pull in the content from the url, which might actually be nicer anyway as if there's lots of results you could lazy load them as the user scrolls. The url you use in js would be something like {$entry->url}&showtemplate=false

_________________
Not getting the answer you need? CMSMS support options


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Wed Sep 05, 2018 5:11 pm 
Offline
Forum Members
Forum Members

Joined: Wed Aug 08, 2018 4:59 pm
Posts: 55
I will try the javascript approach, but honestly I think it's a bit strange that the Search Module is so unflexible. Somehow I thought it would be rather easy to just implement $entry -> content to the foreach loop and then the magic would happen :)


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Wed Sep 05, 2018 5:14 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Feb 25, 2009 4:25 am
Posts: 850
Location: Victoria, BC
Agreed, ideally the alias should be returned to make it easier to obtain the content. You can always put in a feature request at http://dev.cmsmadesimple.org/projects/cmsmadesimple

_________________
Not getting the answer you need? CMSMS support options


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Wed Sep 05, 2018 5:38 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Apr 23, 2008 7:53 am
Posts: 7710
Location: The Netherlands
From default Search result template:
\$1:
{*
You can also instantiate custom behaviour on a module by module basis by looking at
the $entry->module and $entry->modulerecord fields in $entry
ie: {if $entry->module == 'News'}{News action='detail' article_id=$entry->modulerecord detailpage='News'}
*}
This way you can show any News content you want...

_________________
$1

Did my post help you solving a problem at your (customers) website and it saved you many hours of work? Great!! Consider buying me a cup of coffee in return!



Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Wed Sep 05, 2018 5:40 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Apr 23, 2008 7:53 am
Posts: 7710
Location: The Netherlands
Sendlingur \Sendlingur:
\$1:
 <li><a href="{$entry->url}">{$entry->urltxt}</a> ({$entry->weight}%)
     
</li>
{$entry->content}

Note:
{$entry->url}, {$entry->urltxt} and {$entry->weight} are Search module Smarty tags
{$entry->content} is from the News module...
You can't mix them here.

_________________
$1

Did my post help you solving a problem at your (customers) website and it saved you many hours of work? Great!! Consider buying me a cup of coffee in return!



Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Thu Sep 06, 2018 8:43 am 
Offline
Forum Members
Forum Members

Joined: Wed Aug 08, 2018 4:59 pm
Posts: 55
Rolf \Rolf:
From default Search result template:
Quote:
{*
You can also instantiate custom behaviour on a module by module basis by looking at
the $entry->module and $entry->modulerecord fields in $entry
ie: {if $entry->module == 'News'}{News action='detail' article_id=$entry->modulerecord detailpage='News'}
*}
This way you can show any News content you want...


But what if I want to show the first senteces from a page in content manager? would it work the same way?

And Rolf... I'm using the autocomplete search snippet from your website. It is working like a charm but as you know it is searching through titles and obviously it returns both article titles from the news module and page titles from the content manager.

So my problem is basically to show content text, from any possible module.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Thu Sep 06, 2018 4:22 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Apr 23, 2008 7:53 am
Posts: 7710
Location: The Netherlands
Working example

At https://beeldbank.zeijen.nu I use the Uploads module for photo's.
The important part of the Search Result template is:
\$1:
    {foreach from=$results item=entry}
        {if $entry->module == 'Uploads'}
            <div class="grid_2 m_bottom_15">
                {Uploads action='detail' detailtemplate='search' upload_id=$entry->modulerecord}
            </div>
        {/if}
    {/foreach}

I created a detail template in the Uploads module with my needed content:
\$1:
<a href="{$entry->canonical}" title="#{$entry->id} - {$entry->summary|escape:'htmlall'|default:''}">
    {CGSmartImage src="{$entry->origfile_url}" class="uploads_summary_img" filter_croptofit="500,500" filter_watermark=true alt="#{$entry->id} - {$entry->summary|escape:'htmlall'|default:''}"}
</a>

As far as I understand your question, this is what you need. This is for Uploads, but it also works for News, CGBlog, LISE, etc.

This link displays the search content: https://beeldbank.zeijen.nu?zoekwoord=rolf
Five times a result, five times displaying an Uploads detail template

_________________
$1

Did my post help you solving a problem at your (customers) website and it saved you many hours of work? Great!! Consider buying me a cup of coffee in return!



Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Sat Sep 08, 2018 2:09 pm 
Offline
Dev Team Member
Dev Team Member

Joined: Mon Nov 28, 2011 9:29 am
Posts: 3135
Location: The Netherlands
I just checked and it seems IF the 'module' is a content page, neither '$entry->module' nor the '$entry->modulerecord' are provided in the results.

IMO it would make sense to implement this (and probably easy to implement).

Feature request submitted: http://dev.cmsmadesimple.org/feature_request/view/11886


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Wed Dec 05, 2018 4:29 pm 
Offline
Forum Members
Forum Members

Joined: Wed Aug 08, 2018 4:59 pm
Posts: 55
I've been trying to make this work so I can display few lines from the content in the search results. I found this old post with a great answer, but it is not working for cmsms 2.x. It seems to be exactly what I need.

I've been trying to rewrite the answer for cmsms 2.x but with out any luck. I believe I need more experience to be able to rewrite it so it works.

here is a UDT that have to be made (called 'set_alias')

\$1:
/** 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;
}



Here is the code for the search template

\$1:
<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}


Can anyone help me to make this work for CMSMS 2.x?

here is a link to the old post https://forum.cmsmadesimple.org/viewtopic.php?f=7&t=54145

the answer is from a user called uniqu3, maybe he is still active and sees this :)


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Wed Dec 05, 2018 7:10 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Feb 25, 2009 4:25 am
Posts: 850
Location: Victoria, BC
2.3 will allow for accessing the page content in search results
(I don't have an answer for your UDT request, but for reference it won't be needed once 2.3 is out)

_________________
Not getting the answer you need? CMSMS support options


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.  Topic is solved
PostPosted: Thu Dec 06, 2018 7:19 pm 
Offline
Dev Team Member
Dev Team Member

Joined: Mon Nov 28, 2011 9:29 am
Posts: 3135
Location: The Netherlands
UDT:

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

$return = false;

$title = strip_tags($params['title']); // search might add span to title to highlite specific searched words

foreach ($cntnt->GetAllContent(false) as $page) {
 if (strip_tags($page->Name()) == $title) {
   $return = ($page->Alias());
   break;
 }
}

if(!empty($params['assign'])){
       // $smarty = cmsms()->GetSmarty();
        $smarty->assign(trim($params['assign']), $return);
}
else{
        return $return;
}


Sample search result template:
\$1:
<h3>{$searchresultsfor} &quot;{$phrase}&quot;</h3>
{if $itemcount > 0}
<ul>
  {foreach from=$results item=entry}
  <li>{$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a> ({$entry->weight}%)<br />
   {if empty($entry->module)}
     {set_alias title=$entry->title assign='get_alias'} {* call set_alias udt and assign as get_alias *}
     {page_attr key=content_en page=$get_alias assign=result_content}{$result_content|truncate:'160'|strip_tags} {* page_attr 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 *}
  {/if}
</li>
  {/foreach}
</ul>

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


Please test thoroughly before implementing in production environment

Further note that if in future versions the 'module' property of a search result entry is provided for 'content' too - as DIGI3 posted - that this template will fail. You then might need to check for {if $entry->module == 'content' } or something, in stead of {if empty($entry->module)}


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Adding {$entry->content} to search results.
PostPosted: Mon Dec 10, 2018 2:12 pm 
Offline
Forum Members
Forum Members

Joined: Wed Aug 08, 2018 4:59 pm
Posts: 55
Thank you all for your help, I'll test the solution from Velden.

Is there a release date for 2.3?


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.  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: googlebot


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