ListIt2 - identify whether a search form has been submitted

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
gocreative
Power Poster
Power Poster
Posts: 265
Joined: Mon Mar 14, 2011 1:16 am

ListIt2 - identify whether a search form has been submitted

Post by gocreative »

I'm trying to figure out how to show/hide some content based on whether a ListIt2 search has been performed.

Essentially, the LI2 form is on the page along with other content, and I want to hide some specific parts of that content only if the form has been submitted. Unfortunately there doesn't seem to be any variable passed which I could access to do this.

Any other ideas?
uniqu3

Re: ListIt2 - identify whether a search form has been submit

Post by uniqu3 »

Well i guess you do use a different ListIt2 summary template to show search results, so you can create any variable you want in that template.

So let's say you have a ListIt2 search template named "search_results", so you call your ListIt2 instance i guess like {ListIt2MyInstance action='search' template_search='search_form' template_summary='search_results'}, inside that template you pass a variable that search action was performed.

Example:

Code: Select all

{$search_performed = 1} {* assigning search performed variable which can be used later on in page template *}

{if $items|@count > 0}
    {foreach from=$items item=item}
    <!-- the rest of the summary template -->

    {/foreach}

{else}
    <p>Sorry, no results found.</p>
{/if}
Now in your page template you can simply do logic based on that variable we created in summary template.

Code: Select all

{if isset($search_performed)}
   <!-- Search was performed do something here -->
{else}
   <!-- The regular stuff -->
{/if}
Keep in mind, that assigned variable does have to exist before your logic, but if your ListIt2 instance module call happens after that logic, you should assign module tag first, like {ListIt2MyInstance action='search' template_search='search_form' template_summary='search_results' assign='whatever'} and then simply call {$whatever} where module is needed.
gocreative
Power Poster
Power Poster
Posts: 265
Joined: Mon Mar 14, 2011 1:16 am

Re: ListIt2 - identify whether a search form has been submit

Post by gocreative »

Thanks, Goran! Fantastic support, as always. I'll check into this and come back if I have any issues, but it sounds fairly straightforward.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: ListIt2 - identify whether a search form has been submit

Post by velden »

uniqu3 was faster, had about same post.

Want to append that inside LI2 summary template you can check if it's called by 'search action':

Code: Select all

{if $actionparams['search']}{assign var="search_performed" value=1}{/if}
...
Then you could use same template for search results as for normal summary display (if applicable).
Post Reply

Return to “Modules/Add-Ons”