We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1888
    • 9 Posts
    I’ve created a snippet, and I want it to run multiple times on the same page. It runs fine if I call the snippet once, but if I call it twice, it only remembers the parameters from the second instance, not the first. So I end up with two instances with exactly the same output , even though I’ve sent a different set of parameters in the two instances. For example, here is my call to the two instances:

    <h2>Administrative Faculty</h2>
    [[PeopleList?&designation=’Administrative Faculty’&center=1]]

    <h2>Professional Faculty</h2>
    [[PeopleList?&designation=’Professional Faculty’&center=1]]

    When I do this, it returns the values for "Professional Faculty" both times. Is this a normal behavior? How can I change this?
      • 26435
      • 1,193 Posts
      The variables you set in the parameters are parsed before the page output is returned. the second call overwrites the variable data you tried to store with the first call. Can you redo the snippet to use associative array to store the parameter variables? this might be the best option if you need to use multiple calls per page and you don’t want to have multiple copies (named differently) of the exact same snippet.

      -sD-
      Dr. Scotty Delicious, Scientist.
        Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
        All of the above... in no specific order.


        I send pointless little messages
        • 34017
        • 898 Posts
        Scotty,

        Do you know of a simple example or snippet that takes the parameters in associative arrays? I am working with extending ppp and would love to see it be able to be called multiple time on a page.

        Thanks,
        Chuck
          Chuck the Trukk
          ProWebscape.com :: Nashville-WebDesign.com
          - - - - - - - -
          What are TV's? Here's some info below.
          http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
          http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
          • 26435
          • 1,193 Posts
          I don’t know of one off hand, but if you had set towards the top of your snippet $group = array(); then called your parameter like &group[0]=`users` and in the next one &group[1]=`bosses` then do a foreach on the group array before returning the output.

          I haven’t tried it, but that should work.

          -sD-
          Dr. Scotty Delicious, Scientist.
            Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
            All of the above... in no specific order.


            I send pointless little messages
            • 34017
            • 898 Posts
            Thanks Scotty.

            I will try it out and let ya know.

            Chuck
              Chuck the Trukk
              ProWebscape.com :: Nashville-WebDesign.com
              - - - - - - - -
              What are TV's? Here's some info below.
              http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
              http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
              • 1888
              • 9 Posts
              Hi all
              I jus fugured out what the problem was - i was using the snippet to replace a chunk variable by $modx->setPlaceholder(), which was creating the problem. I used ereg_replace() instead and now it works fine.
              Thanks for ur help anyway.
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: apatkar at Nov 17, 2006, 12:48 PM

                Hi all
                I jus fugured out what the problem was - i was using the snippet to replace a chunk variable by $modx->setPlaceholder(), which was creating the problem. I used ereg_replace() instead and now it works fine.
                Thanks for ur help anyway.

                You can replace chunk-specific tags by using the $modx->parseChunk() API function. This is not currently in the API documentation for some reason, but is quite easy to use. See http://modxcms.com/forums/index.php/topic,6483.msg45854.html#msg45854 for a forum post with the details.