I haven’t been able to find this, but I know someone out there who knows PHP could whip it up in no time.
I’d like to have a snippet which calls a chunk and inserts a file.
I’d call it like this:
[tt][[Filepass?chunk=`MyChunk` &file=`/assets/media/whatever.mov`]][/tt]
Then in [tt]MyChunk[/tt], I could use [tt][+file+][/tt] and it would get replaced with the [tt]&file[/tt].
This would be great for me when I need to embed several flash players in a page, where all that changes is the file being referenced.
Anyone?
OK, now could someone help me make this so I could pass multiple placeholders?
Something like:
[tt][[Chunker?tpl=`wow` &ph=`var1,var2,var3` &z=`dog,cat,808`]][/tt]
Can it be flexible to allow any number? (I can do it myself for only three!)
-
☆ A M B ☆
- 24,524 Posts
Yes, in your snippet code use explode() to get the individual items from the parameter into arrays, then loop through the arrays setting the placeholder for each one. This would only work as long as your two parameters have the same number of individual items in the same order:
$pharray = explode(',', $ph);
$zarray = explode(',', $z);
for($i=0;$i<count($pharray);$i++) {
$modx->setPlaceholder($pharray[$i], $zarray[$i]);
}
...
I was just going to give the same answer but, as so often happens, sottwell beat me to it so here’s another solution that will only work in PHP5:
$pharray = explode(',', $ph); // make an array from the &ph parameter
$zarray = explode(',', $z); // make an array from the &z parameter
$combined_array = array_combine($pharray,$zarray); // make one big associative array from both
foreach($combined_array as $key=>$value) {
$modx->setPlaceholder($key,$value);
}
I’m fairly confident that sottwell’s solution will be faster and use less memory -- and it works in PHP4 -- so mine is just for your amusement.
-
☆ A M B ☆
- 24,524 Posts
Definitely intelligent design