Forums › Forums › Search & Filter Pro › Conditional Tags, AJAX, and Results.php
- This topic has 5 replies, 2 voices, and was last updated 9 years, 1 month ago by Anonymous.
-
Anonymous(Private) October 20, 2015 at 3:41 pm #27773
Hi,
I’m using Timber to render Twig templates to format my search results via results.php. I’ve added a conditional tag to load a new twig template if a specific page is calling the search results.
results.php:
<?php
if (is_page(ID)) {
$templates = array(‘special-template.twig’);
} else {
$templates = array(‘general-template.twig’);
}….
This works fine on “Special Page” — i.e. the special-template results are loaded. However, I want to use AJAX to filter the results. When I try an AJAX filter, is_page returns FALSE and the “general-template.twig” is loaded for my search results.
Any advice? Or is this the wrong approach for what I want to accomplish?
Thanks!
Ross Moderator(Private) October 23, 2015 at 4:41 pm #28080Hey there
I see the issue, I’m going to add a method/var to the query, which will return the Search Form ID – so you can do a check in your loop against the search form ID, and load the correct template based on that.
Sound like what you need?
Thanks
Ross Moderator(Private) October 27, 2015 at 11:40 am #28299Yup, I’ll try add it in today / tomorrow
Ross Moderator(Private) October 27, 2015 at 3:59 pm #28337Just emailed you an update.
If using in results.php you should use:
echo $query['search_filter_id'];
Thanks
Anonymous(Private) October 28, 2015 at 3:49 pm #28447Excellent! It works!
I had to access the ID via the object property; the array index wouldn’t work — not sure if that’s a bad sign or not.
$sf_id = $query->query[‘search_filter_id’];
if ($sf_id == ‘XXX’) {
$templates = array(‘page-specific.twig’);
} else {
$templates = array(‘general.twig’);
}Thanks again!
-
AuthorPosts