We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I’ve run into a problem. I’m trying to pass a variable gathered by a snippet or a TV as an argument to a snippet.

    [[WebLogin? &logouthomeid=[[id]] &tpl=...]]

    or

    [[WebLogin? &logouthomeid=[*id*] &tpl=...]]

    I’ve tried it with and without backticks `[[id]]`

    Using a snippet doesn’t work at all, snippet command parsing stops at the first ]] it finds (understandably enough, I suppose; I could live with not being able to nest snippets), but using a TV makes the parser complain that [*id*] is not numeric etc etc. Both the snippet and the TV do in fact return the desired value.

    Now what "gets" me is that the TV works just fine with snippets that are called in the template! But if it’s done in a chunk, or in document content, it doesn’t work at all, not even the menu snippets.

    If I put the WebLogin snippet in the template, it works fine as long as I enclose the TV in backticks. Otherwise, it complains that `1` is not numeric etc etc.
      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
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I figured out why I was having some of the problems last night. I was using a different template for the NewsPublisher snippet, and calling the WebLogin snippet from within the document content. As long as I call it from the template and not in the document content, it’s OK.

      I’m also using the [*lang*] TV as the value for the id argument in the ListMenuX snippet. This works in the template. It does not work in a document’s content; value of 0 is used instead, which is a bit odd since the default is documentIdentifier, and the ID of the document this is tested on is 26. Even the default for the TV is site_start, in this case 1. Coding the TV to echo its value shows the correct value.

      What’s really weird is that I added lines to echo the $id variable in the WebLogin snippet itself, and it’s displaying the correct values. So where is the 0 that it’s using coming from huh

      I put a print_r($params) in the document parser, line 664, where it parses snippets and gets an array of params. For the ListMenuX snippet that is called in the document body, it shows [*lang*] as the id value. The other two menus, called from the template, are fine, as is the WebLogin args, also called from the template. So in the document content, the TV call inside the snippet call is not getting parsed, but is being passed verbatim as the param value.

      After playing around with links and other stuff, TVs in general work fine. They just don’t get parsed if they are used as an argument value for a snippet call in the document content.
        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