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
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 !
Not sure it’s the solution but you can try an uncached call: [!listerDepartsVoyage? &idVoyage=`[*id*]`!]
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.
-
☆ 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.