CMS Made Simple Forums
https://forum.cmsmadesimple.org/

How to find all keyword occurencies directly from content
https://forum.cmsmadesimple.org/viewtopic.php?f=4&t=69724
Page 1 of 1

Author:  osxfil [ Thu Mar 20, 2014 8:48 am ]
Post subject:  How to find all keyword occurencies directly from content

Maybe you sometimes think how to find all keyword occurencies directly from article on your website instead searching with search form. It is useful e.g. for wiki-based sites etc.
I got this idea during releasing website for Holovitalis.de (natural healing). They want to have on their website wiki-based section called Lexikon (created with CGBlog module) with FEU submit of articles. One of customer requirements was possiblity for searching all keyword occurencies accross whole website.

1. UDT
Create UDT called "keyword":

\$1:
$contentobj = cms_utils::get_current_content();
$page_title = '';
if (is_object($contentobj))
{
   $page_title = cms_htmlentities($contentobj->Name());
}
if ($page_title != "Neuer Artikel") { //$page_title variable change to page title where is your articles FEU submit form
$key = $params['key'];
$link = "suchen"; // page alias for search results
echo("<a href=\"".$link."?keyword=".$key."\">".$key."</a>");
} else
echo("{keyword key=\"Your keyword\"}");


What UDT does?
UDT convert your searched keyword to the link to page where you want display search results. Additionally provide that you can add instruction how to use the tag to the page with FEU articles submit form, for example:
\$1:
If you want in your article to use searching for a keyword in the lexicon, in magazines or in the site content, use this tag: {keyword key="Your keyword"} and replace "Your keyword" with text for searching.


Searching template
Additionally update your searching template:
\$1:
{capture assign='term'}{$smarty.get.keyword}{/capture}
{if $term !=''}
{$startform}
<input type="text" class="search-input" id="{$search_actionid}searchinput" name="{$search_actionid}searchinput" size="20" maxlength="50" value="{$term}"/>
{if isset($hidden)}{$hidden}{/if}
{$endform}
{literal}
<__script__ type="text/javascript">
  window.onload=function(){
    document.forms["cntnt01moduleform_1"].submit();
  }
</__script>
{/literal}

{else}
{$startform}
<input type="text" class="search-input" id="{$search_actionid}searchinput" name="{$search_actionid}searchinput" size="20" maxlength="50" value="{$searchtext}" {$hogan}/>
{if isset($hidden)}{$hidden}{/if}
{$endform}
{/if}

(please delete __ before and after "script")
Search form providing auto-submit in case URL parameter "term" is exists. If is URL param "term" empty or if not exists, standard search from will displayed.

How to use
Using of this feature is very simple. Each allowed backend users (admins, editors…) and FEU users (if you have allowed submiting articles by FEU) can use this tag directly on their text:

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque vel arcu mollis arcu lacinia pulvinar consequat nec libero. {keyword key="Curabitur"} ullamcorper ullamcorper libero sit amet vestibulum. Mauris nulla enim, consequat aliquam rhoncus ut, rutrum vulputate justo. Donec tellus justo, mattis quis laoreet eget, malesuada ut augue. Nam aliquam malesuada sagittis. Morbi ante quam, feugiat sit amet euismod ac, tristique non dui. Quisque at sem leo. In hac habitasse platea dictumst. Donec imperdiet nulla id nulla imperdiet iaculis. Morbi nec erat est, vitae laoreet dui. Morbi lobortis augue eu magna luctus vitae molestie lectus eleifend. Ut est nisl, tincidunt eu tempor in, eleifend<a href="{cms_selflink href='a'}">volutpat</a> augue. Nam aliquet auctor felis ac feugiat. Quisque aliquet purus a felis malesuada fringilla.</p>

Live example: go to http://develop.bocekmedia.net/2013/09/Ferrum-metallicum and click to "Curabitur" keyword

Author:  chandra [ Thu Mar 20, 2014 1:24 pm ]
Post subject:  Re: How to find all keyword occurencies directly from conten

Thx for sharing this - very helpful.

By the way - with Smarty 3 you can make things like this

osxfil \osxfil:
\$1:
{capture assign='term'}{$smarty.get.keyword}{/capture}



a lot shorter ;)

\$1:
{$term = $smarty.get.keyword}

Author:  osxfil [ Thu Mar 20, 2014 2:20 pm ]
Post subject:  Re: How to find all keyword occurencies directly from conten

Yeah, sure. Force of habit ;)

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/