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.

Combining input/output PHP processing in a single template, possible with a plugin, or other means?

November 03, 2009 6:35pm

Subscribe [3]
  • #1 / Nov 03, 2009 6:35pm

    timkelty

    177 posts

    I’m finding myself all to often resorting to embedding an entirely new template, simply because I need something parsed with PHP on input (usually to inject segments, GET/POST, Date, Session/User data into parameters), when other parts of my template require output processing, or vice versa.

    Performance wise, it seems wasteful to have to embed an entirely new template, and is also cumbersome to have a chain of embedded templates.
    Is it conceivable to have a plugin that would parse it’s contents on input or output depending on a parameter?

    I’m happy to dig in to developing one, but I wanted to know if anyone has tried, if its even possible with a plugin, or if the parsing already too late to be done by a plugin?

    Example:

    {exp:weblog:entries entry_id="{exp:php parse="input"}<?= $_GET['country'] ;?>{/exp:php}">
        {exp:php parse="output"}
            <?php $states[] = '{state_code}'; ?>
        {/exp:php}
    {/exp:weblog:entries}
        
    {exp:php parse="output"}
        <?php
          $states_str = implode('|', $states);
          echo($states_str);
        ?>
    {/exp:php}
  • #2 / Nov 03, 2009 7:04pm

    Adam Dorsey

    1439 posts

    Hi timkelty-

    This isn’t really a “Tech Support” issue, so I am going to move this to the “How to” forum.

    Our amazing community will likely have some great input for you. Thanks!

  • #3 / Nov 04, 2009 9:49am

    ender

    1644 posts

    plugins are EE tags like any other, so if you need PHP executed before the template tags then a plugin will already be too late.

    embeds are also run after the template they are embedded on, so that eliminates running input php that occurs before your main template in an embedded template.

    here are your choices:
    1) using one template that performs some php code and then 301 redirects to a second template
    2) doing your input processing on your main template and then embedding the php that needs to run in output mode
    3) doing your input processing on your main template and implementing your output mode php functionality as a plugin (may or may not work depending on what you’re doing with the PHP and how it relates to the other template tags)

    for whatever it’s worth, embedding templates just adds another (fairly light-weight) query or maybe two to the page. in terms of performance optimizations this should be pretty much last on your list.

  • #4 / Nov 04, 2009 10:07am

    timkelty

    177 posts

    Thanks for the response! As I suspected, no magic bullet…

    My concern about embeds came from Solspace’s Performance Guidelines recently released:

    Effectively, an embedded template is a sub-page within a page, and it requires all of the processing that building a page from a template entails.  It is not a lightweight operation.

  • #5 / Nov 04, 2009 10:20am

    ender

    1644 posts

    there’s definitely some query and processing overhead involved, but if you need that code to be run anyway and you’re not doing anything extra that you wouldn’t have done anyway it ought to be fine.  Use embeds, just don’t overuse them imo.  Kinda goes back to the rule of thumb with any optimization: write code that works, don’t worry about things that *might* become performance issues until you’ve measured that they are indeed a performance issue.

    And in this case, the best measurement tool is to turn on template debugging and look how long each step takes the server to complete.

  • #6 / Nov 04, 2009 10:52am

    Mark Croxton

    319 posts

    Why not nest your plugins/modules (and use parse=“inward” on the outer tag pair)? The outer tag can parse any content it wraps, so for example you can set the parameters for plugins/modules contained within.

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

ExpressionEngine News!

#eecms, #events, #releases