I have a snippet that returns a single value. Now from my understanding, instead of returning the value, I can have
$modx->setPlaceholder($placeholdername, $value);
And then somewhere call it:
I’ve done this, and am trying to use the placeholder as an argument to a snippet:
$modx->setPlaceholder('UltimateParent',$id);
[[DropMenu?startDoc=`[+UltimateParent+]`]]
and it’s not working. What am I missing?
Works perfectly if I just return the value and call it as a snippet, so I know my value is good.
-
- 1,732 Posts
snippets are processed before placeholders that’s why the value was not passed to the snippet
so you can’t use a placeholder to pass a value to a snippet. Ok, no big deal, the snippet works just fine returning the value.
-
- 1,732 Posts
Quote from: sottwell at Nov 03, 2005, 03:57 PM
so you can’t use a placeholder to pass a value to a snippet. Ok, no big deal, the snippet works just fine returning the value.
Not at this point in time. But if you add it as a feature request we can look into the possiblity of doing such a thing.
It would be handy, because you can’t use a snippet to pass a value in a snippet with the normal tags, you have to have the outer tags in the [!...!] form. Otherwise, the parser stops at the first set of inner ]] tags and you end up with a malfunctioning snippet and ]] displayed on your screen!
-
- 302 Posts
OK, another forum member and I have been chatting about placeholders, and honestly... neither of us know what the heck they are. Documentation is sparse, and they don’t seem to be a very popular subject in these forums. Anyone want to offer a 2 minute tutorial?
Standard Disclaimer
I could be totally wrong.
-
- 680 Posts
Placeholders are a fairly advanced. Basically you set them in your code and they are reflected in the template. We are talking about using them a bit more widely, at that point we should also put up some better documentation.
I’ll have some new examples of placeholder usage in some components I’m preparing to release soon. I use these placeholders extensively in building dynamic forms, providing dynamic output into pages where the surrounding markup is easily modified by designers as well as into templates provided in the component configuration (e.g. so the even dynamic output sections can be modified easily as a chunk without changing the more complex snippet code).
I really began to appreciate the value of placeholders when working with the new NewsListing; the default template uses placeholders to control its output, and I didn’t want the author and date to show on one "teaser" block I was making. It was simple to just make a template without the author and date placeholders, and get exactly what I wanted. With the old version, I had to hack the code and use two separate versions of the snippet!
The one thing I did do, though, was add another argument to specify if I wanted the archive list or not, and inclosed the archive list code in an "if" conditional block. I’m considering adding another argument ( &showRandom maybe) and a block of code to display a single, random article; this would be useful for a front page news block, a "client quotes" block, or a random bit of poetry, advice, wise saying, image, random Student of the Month profile, or anything else you can imagine putting in a document.