Page 1 of 1
ListIt2 - identify whether a search form has been submitted
Posted: Thu Jun 26, 2014 3:53 am
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?
Re: ListIt2 - identify whether a search form has been submit
Posted: Thu Jun 26, 2014 8:06 am
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.
Re: ListIt2 - identify whether a search form has been submit
Posted: Thu Jun 26, 2014 8:10 am
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.
Re: ListIt2 - identify whether a search form has been submit
Posted: Thu Jun 26, 2014 8:14 am
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).