We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7575
    • 85 Posts
    I am trying to test snippets.
    (I useMODX Revolution 2.2.0-pl2 (traditional))
    I want to pass a variable to the snippet (first) and show it
    and put the values of the TV into an array (Array [0] => 1 [1] => 2 [2] => 3 [3] => 4 ... )

    template varialbe "subcategories":
    1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18
    call to snippet:
    [[lijst? &first=`inhoud`]]

    snippet
    <?php
    echo "the passed variable:".$first."
    ";
    print_r(explode(" ","[[*subcategories]]"));

    result on screen:
    the passed variable:
    Array ( [0] => 1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 )

    2 problems:
    The $first variable is not shown.
    and
    the array is shown but does not explode correctly...

    as this is basic functionality of modx revolution
    I guess I am doing something wrong?
    [ed. note: djemmers last edited this post 12 years, 2 months ago.]
      www.tornooi.net online database for (sport) events in dutch.
      To be redesigned, rewritten to modx with multiple languages...
      ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.
      • 3749
      • 24,544 Posts
      You can't use snippet tags in PHP code -- PHP doesn't know what to do with them. You can either pass the TV in another property:


      [[lijst? &first=`inhoud` &tvvalue=`[[*subcategories]]` ]]



      or you can get the value directly in the snippet:

      $tvValue = $modx->resource->getTVValue('subcategories');



      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 7575
        • 85 Posts
        tnx,
        I got it working!
        a small tip if you are using TinyMCE,
        watch out for html that sneaks into your snippet calls (copy paste...)

        that was the reason why it didn't work with me...
          www.tornooi.net online database for (sport) events in dutch.
          To be redesigned, rewritten to modx with multiple languages...
          ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.