We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39357
    • 13 Posts
    Hi all

    I have a weird problem with passing varibles from snippets.
    I've done this loads of times using something like:

    mydomain.com/something.html?variable=somevalue


    then to get the variable in a snippet I use GET:

    $variable = isset($_GET['variable']) ? $_GET['variable'] : '';


    This typically works fine, but now I have a page where the variable wont update.

    I have a page, lets call it "list.html", populated with entries from a DB, and they are all ordered as links like this:

    <a href="/something.html?VariableId=1">DB item 1</a>
    <a href="/something.html?VariableId=2">DB item 2</a>
    <a href="/something.html?VariableId=3">DB item 3</a>
    


    Then at page "something.html" I have a snippet which uses the VariableId passed in the URL, like this:

    $VariableId = isset($_GET['VariableId']) ? $_GET['VariableId'] : '';
    
    echo $VariableId;
    


    This works the first time, but when I enter "list.html" again and press another link, the echoed variable is the same as before.
    Fx. If I press the link for DB item 1 the first time, the snippet at "something.html" will echo "1". When I return to "list.html" and press the link for DB item 2, the echoed value is still "1"


    Am I missing something, or does anyone know why the variable does not seem to be updated to the proper value sent by the URL?

    Thanks in advance for all answers smiley

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      Are you calling the snippet uncached? [[!snippet...]]
        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
      • discuss.answer
        • 39357
        • 13 Posts
        Yes like [[!MySnippet]]

        What else could I do?
          • 39357
          • 13 Posts
          Quote from: tuetue at Jun 16, 2013, 04:49 PM
          Yes like [[!MySnippet]]

          What else could I do?


          sorry, I checked my code all over, and no, I didnt call it uncached even though i normally always do. My mistake, and thanks for pointing me in the right direction smiley
          • Snippets shouldn't use "echo", you should return the output.

            You do have Friendly URLs turned on?
              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