ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

PHP parsing on output doesn’t seem to be working

December 21, 2008 9:44am

Subscribe [1]
  • #1 / Dec 21, 2008 9:44am

    oli-studio

    19 posts

    Hi All,

    I’m trying to apply a PHP function to a template’s entire contents, and have enabled PHP and set it to parse on output. However it seems an embedded template in the template isn’t processed before PHP parsing occurs. Can someone tell me what I’m doing wrong?

    <?php
    $input = <<<EETAG
    {embed="test/embed"}
    EETAG;
    
    echo preg_replace('/embed/','cheese',$input);
    ?>

    I assume that ‘parse on output’ should mean the EE tag is expanded (into the content of the test/embed template) *before* preg_replace occurs, but the output I get is “{cheese="test/cheese"}“. If I just echo $input without preg_replace I do get the embedded template’s contents.

    Alternatively if I’m doing it wrong can someone reply with pseudo-code to apply a PHP function to a ‘rendered template’?

    Thanks in advance

    peace - oli

  • #2 / Dec 21, 2008 4:05pm

    Greg Aker

    6022 posts

    oli-studio:

    What is your goal here?  Perhaps there is native solution to what you are trying to do.

    -greg

  • #3 / Dec 21, 2008 9:23pm

    oli-studio

    19 posts

    Hi Greg,

    I’m trying to convert UTF-8 content into a different encoding (Shift-JIS) for use in a mobile version of the website, using PHP’s iconv function. I tried making a plugin, but while it works with the content of the template it didn’t have any effect on embeds, leading me to wonder if plugins are applied before embeds. So now I’m trying to use PHP to affect the “rendered Template”, and even with PHP set to ‘parse on output’ for the template, it just doesn’t seem to be doing so.

    I should be able to assign the result of the template (post-EE tag processing) to a variable then apply a PHP function to the variable shouldn’t I? Is there some kind of buffer that EE is using or something? Alternatively is there something I can do to the plugin to get it to work as expected?

    Any assistance would of course be greatly appreciated 😊

    peace - oli

  • #4 / Dec 22, 2008 11:32am

    Pascal Kriete

    2589 posts

    It’s a parse order problem.  If you take a look at that link, you’ll see that the sub-templates are done after php on-output.

    The only thing that comes to mind right now is to wrap the whole template in the iconv code.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases