We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19368
    • 40 Posts
    Hey team,

    I am sure I will find an answer to this here.

    [UPDATE before you try to solve this I have, but it might be worth the read to see the answer and you might be able to explain why]

    Having recently discovered the power of TVs I am putting them into practise by adding some values to different pages based on the TV

    I have set up the TV named pagename with
    about==about||baby==baby||boys==boys||contact==contact|
    OK so far.

    I have a snippet called setpage in each page
    [[setpage? &page=`[*pagename*]`]]
    and then choose the TV

    The snippet looks like this
    <?php
    echo $page . " - " ;
     
    switch ($page){
    case about:
    echo "about";
    break;
    
    case 'baby':
    echo "baby";
    break;
    
    case "boys":
    echo "boys";
    break;
    
    }
    ?>


    The result is that I see the echoed value perfectly, i.e. the TV is passing through to the snippet. BUT I just can’t get the switch to work.

    I am pretty experienced with PHP so am fairly certain there is no problem with the switch code, but it isn’t hitting the right ’case". If I put in a default it does hit that.

    I have tried just about every workaround I can think of, single, double and back quotes. redefining the variable, singe = rather than double...I have now run out of ideas but know someone here will spot the problem.

    he hopes...

    thanks in advance.

    So...as I previewed this and saw my snippet call I suddenly thought..."cache" and changed the call to [!setpage? &page=`[*pagename*]`!]

    Needless to say it worked...sigh...

    Is it just me or is the modx cache too "aggressive"?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      No, the MODx cache does its job, which is to cache a processed resource’s output so it doesn’t need to be fetched from database and processed on every request. That is why there are cached and uncached forms for snippets (and for every tag in Revolution), so the user can decide whether the snippet’s output should be cached or not.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org