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

    I wonder if it is possible to take the current document id like that [~id~] inside the content area of a document
    so that i can past it directly to the snippet in the same area exemple : [[MySuperSnippet? &docid=[~id~]]].

    The goal of doing this is that i want to use that technique so that don’t need to copy and paste it in each content
    area of each document that i will create in the future. I want to put that in a template so that it’s run by that template
    and it apply the snippet to every document with that template
      • 3036
      • 6 Posts
      Using this [[listerDepartsVoyage? &idVoyage=`[*id*]`]]

      i’am able to pass the id of the current document and the snippet receive the value without a problem
      because i test with an echo but when i’am trying to get the child documents like that :

      $enfants = $modx->getDocumentChildren($idVoyage, 0, 0, ’id’);

      it doesn’t work but when i replace [[listerDepartsVoyage? &idVoyage=`[*id*]`]] by [[listerDepartsVoyage? &idVoyage=22]]

      it does work that is kind of bizzare. I don’t understand why can you help me please ?

      **** Note : the child document of id = 22 are not published so i’am presuming that the second parameter if getDocumentChildren is fine !
        • 8894
        • 114 Posts
        Not sure it’s the solution but you can try an uncached call: [!listerDepartsVoyage? &idVoyage=`[*id*]`!]
          • 3036
          • 6 Posts
          That is working but i don’t understand why is that working!
          what if the difference between double brace and single brace ?

          great useful help for my first post thank you so much !
          i will ask you more stuff coming so be ready my brethren.

            • 7231
            • 4,205 Posts
            It has to do with the parser. For some things it needs to do a first pass to get initial data and if cached it will not do this pass. This is a simplified answer but is a deep as I understand rolleyes
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don't know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 3036
              • 6 Posts
              Quote from: dev_cw at Feb 13, 2008, 02:09 PM

              It has to do with the parser. For some things it needs to do a first pass to get initial data and if cached it will not do this pass. This is a simplified answer but is a deep as I understand rolleyes

              i understand now as deeply as you !
              thank you !
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                When the parser goes through a document it runs all the [[SnippetName]] code through the eval() function to run the PHP in the snippet as it comes to them. So if both snippets are [[SnippetName]] style, the value of the inner snippet is evaluated AFTER the outer snippet, but the outer snippet needs the returned value of the inner snippet to run!

                If you have [!OuterSnippet? &myParam=`[[InnerSnippet]]`!] the [!OuterSnippet is skipped, the [[InnerSnippet]] gets evaluated and its tags are replaced by its returned value. Then at the end, the parser sees that there is now [!OuterSnippet? &myParam=`value`!], converts the [! and !] tags to [[ and ]], and runs the document through again, this time evaluating [[OuterSnippet? &myParam=`value`]] and it works.
                  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
                  • 3036
                  • 6 Posts
                  Quote from: sottwell at Feb 13, 2008, 10:52 PM

                  When the parser goes through a document it runs all the [[SnippetName]] code through the eval() function to run the PHP in the snippet as it comes to them. So if both snippets are [[SnippetName]] style, the value of the inner snippet is evaluated AFTER the outer snippet, but the outer snippet needs the returned value of the inner snippet to run!

                  If you have [!OuterSnippet? &myParam=`[[InnerSnippet]]`!] the [!OuterSnippet is skipped, the [[InnerSnippet]] gets evaluated and its tags are replaced by its returned value. Then at the end, the parser sees that there is now [!OuterSnippet? &myParam=`value`!], converts the [! and !] tags to [[ and ]], and runs the document through again, this time evaluating [[OuterSnippet? &myParam=`value`]] and it works.

                  Men that’s deep enough for the RECURSIVITY lol thanks a lot !