Forums Forums Search & Filter Pro Conditional Tags, AJAX, and Results.php

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #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
    #28080

    Hey 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

    Anonymous
    #28089

    Aha! Yes that makes sense. I didn’t think of checking the Search Form ID—that’ll totally work. Much appreciated! This is a new method you’ll have to write?

    Ross Moderator
    #28299

    Yup, I’ll try add it in today / tomorrow

    Ross Moderator
    #28337

    Just emailed you an update.

    If using in results.php you should use:

    echo $query['search_filter_id'];

    Thanks

    Anonymous
    #28447

    Excellent! 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!

Viewing 6 posts - 1 through 6 (of 6 total)