-
- 73 Posts
Hi,
what is the best way to produce a certain output depending on the value of a tv, when the possible values are known? Like, think of a single-choice dropdown TV that lets you choose the slider version.
For option 'Nivo', you want to insert a bit of js in the header, and a certain chunk in the body.
For option 'Cycle', you want to insert some other js, and some other chunk.
And for option 'None', you want to insert nothing in both places.
What's the most elegant way to do that?
[ed. note: neo2.0 last edited this post 12 years, 7 months ago.]
PHP illiterate MODx enthusiast
Write a Snippet with that logic?
-
- 73 Posts
I suppose there's no simple way to do it exclusively with output modifiers and without new snippets?
I don't know any php. Yet, at least.
PHP illiterate MODx enthusiast
-
- 249 Posts
I'm wondering if you could do a code block something like so. Horribly inefficient because it processes every tag regardless of logic, but absent PHP coding you have to work with output filters however creatively you can. You may need to prepend a question mark to prevent caching: [[
!*MyTv....
<head>
[[*MyTV:equals=`OptionValue1`:then=`[[$ChunkWithJS1]]`:else=``]]
[[*MyTV:equals=`OptionValue2`:then=`[[$ChunkWithJS2]]`:else=``]]
...
</head>
<body>
[[*MyTV:equals=`OptionValue1`:then=``[[$HTMLChunk1]]`:else=``]]
[[*MyTV:equals=`OptionValue2`:then=``[[$HTMLChunk2]]`:else=``]]
...
</body>
lo9on.com
MODx Evolution/Revolution | Remote Desktop Training | Development
-
- 73 Posts
Yeah, that's in the ballpark of what I have been achieving, even though this exact solution has been escaping me.
I guess that it would be quite a snap for a true PHPero to squeeze that into a few lines, wouldn't it?
I'd love to know how that looks in PHP. Would help me to come up with something of my own next time around.
PHP illiterate MODx enthusiast
-
- 5,888 Posts
I'm not sure if this will work. You can try this:
If your options are Nivo||Cycle||None
create chunks headNivo,headCycle,headNone and bodyNivo,bodyCycle,bodyNone
and call it with
or
if this doesn't work this should:
snippet 'showchunk':
<?php
return $modx->getChunk($prefix.$name);
[[!showchunk? &prefix=`head` &name=`[[*yourTV]]`]]
[[!showchunk? &prefix=`body` &name=`[[*yourTV]]`]]
-
- 73 Posts
Cool, that looks like what I imagined
Thanks! I am going to try that out tomorrow, will be fun.
I'll tell you how it went.
PHP illiterate MODx enthusiast
-
- 73 Posts
Well, what can I say:
It just works! My first custom snippet
So cool, I'm sold on PHP
PHP illiterate MODx enthusiast
-
- 249 Posts
Bruno17, that is really slick. I never knew you could call chunks with a dynamic name like that. I suppose that would apply for any MODx tag? Such a unique feature, that should really be in the docs.
Quote from: Bruno17 at Sep 22, 2011, 06:53 PMI'm not sure if this will work. You can try this:
If your options are Nivo||Cycle||None
create chunks headNivo,headCycle,headNone and bodyNivo,bodyCycle,bodyNone
and call it with
lo9on.com
MODx Evolution/Revolution | Remote Desktop Training | Development