We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21872
    • 95 Posts
    I want to load a video in a modal window when js is enabled. The way to do this that makes sense to me is to link to a resource that contains the video. Rewrite that link with JS to include an "ajax" parameter in the query string. If the value is 1, return just the resource content, if it is anything else, return the resource as usual. It seems like it would be easy. I tried half a dozen custom snippets but could only ever get it half right. That is, either it would show the content when it was supposed to, but would not show the resource when the ajax parameter wasn’t passed or vice versa. On the grounds that I have a very tenuous understanding of PHP, I got rid of my custom IfAjax snippet and used the If addon, like this:
    [[!If? &subject=`[[!isAjax]]` &operator=`==` &operand=`1` &then=`[[*content]]` &else=`[[$theTemplateCode]]` ]]

    all that isAjax does is this:

    $ajax = $_GET["ajax"];
    if ($ajax == ’1’) {
    return 1;
    } else {
    return 0;
    }

    If the &else is a string or simple chunk, there isn’t a problem.

    So, clearly this is the wrong way. What is the right way?