0

I seem to be a bind. I have this code below

...
foreach ($items as $item)
{

    ?>
    {exp:channel:entries
        channel="foo"
        search:field_name="<?php echo $item['some_key']; ?>"
        limit="1"
    }
        {if no_results}
            <td>None</td>
            <td>0.0</td>
        {/if}
        <td>{some_cost}</td>
        <td>
            <?php
                $price = number_format( floatval("{some_cost}") + floatval("{some_margin}"), 1);
                echo $price;
            ?>
        </td>
    {/exp:channel:entries}
    <?php 
}
...

As you can see, I need to pass the value of a PHP variable into the channel entries tag. For this case, we want PHP to parse early, before EE tags. So that means PHP parsing stage should be set to "input"

But I also need to get the values of the EE tags inside the channel entries and compute them in PHP. However, that means that we want PHP to parse late, after EE tags are parsed. That could be done if PHP parsing stage should be set to "output"

Obviously, I can't set PHP parsing stage to both values.

Is there a way around this problem?

1 Answer 1

3

Do this right way - do not follow the dark side.

Put all your php code into plugin. Your code is not good even from optimization way - not good solution to loop the channel entry. Just make function which will return list of

$item['some_key']|$item['some_key']|$item['some_key']|$item['some_key']

In this case you will do only one request of channel:entry. For calculation

$price = number_format( floatval("{some_cost}") + floatval("{some_margin}"), 1);

make one more function or use exist plugin (like MX Calculator);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.