Quote from: BobRay at Mar 02, 2011, 05:21 AM
I think you’ll need to write your own snippet with its own internal iterator. You can send a comma-delimited list of the TV names and just iterate through them, adding to the output and, for every other one, adding the class name, using if($iterator%2). It will be a lot faster than using PHX. PHX conditionals are very slow and hog a lot of resources.
It would look something like this
[!Iterator? &specs=`Spec1,Spec2,spec3,Spec4`!]
<?php
/*Iterator snippet */
$iterator=0;
$allSpecs = explode(',', $specs);
$output='';
foreach($allSpecs as $spec) {
$output .= '<li';
if ($iterator%2) {
$output .= ' class="even "';
}
$iterator ++;
$output .= '>[*' . $spec . '*]</li>' . "\n";
}
return $output;
Awesome solution, thank you!
But I had to modify the snippet call and still use pxh inside it because I lost ability to check if the [*Spec1..2..*] exists. So I did:
[!Iterator? &specs=`[*Spec1:isnot=``:then=`Spec1`:else=``*],[*Spec2:isnot=``:then=`Spec2`:else=``*],[*Spec3:isnot=``:then=`Spec3`:else=``*],[*Sepc4:isnot=``:then=`Spec4`:else=``*]`!]
and in the snippet I check if Spec is not empty and if it doesn’t I check what description name Spec has and publish it in the same <li>:
<?php
/*Iterator snippet */
function description($anyspec)
{
switch ($anyspec) {
case 'Spec1':
return "Mass";
break;
case 'Spec2':
return "Weight";
break;
case 'Spec3_cost':
return "Color";
break;
case 'Spec4':
return "Smell";
break;
}
}
$iterator=0;
$allSpecs = explode(',', $specs);
$output='';
foreach($allSpecs as $spec) {
if($spec!=''){
$output .= '<li';
if ($iterator%2) {
$output .= ' class="even "';
}
$iterator ++;
$output .= '><table><tbody><tr><td class="title">'.description($spec).'</td><td class="body">[*' . $spec . '*]</td></tr></tbody></table></li>' . "\n";
}
}
return $output;
?>
Everything works great! Thank you!