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.

Parse embed tags before PHP (on output) - FAIL

May 27, 2011 6:37pm

Subscribe [3]
  • #1 / May 27, 2011 6:37pm

    Poccuo

    22 posts

    Hi,

    I am trying to output my entire HTML file (doctype, html, body, etc.) as a single block of code that is selectable. Put more directly I’m creating a CMS that builds eBlast templates and allows my client to copy/paste the code from EE into their EMS of choice. The following code has failed.

    <?php echo htmlspecialchars('{embed="/newsletters/html/"}')?>

    My template is set to accept PHP and parse on output. I understand that EE parse order does embed templates after the PHP Output. So here I am stuck.

    I haven’t been able to find any plugins or solutions to help me overcome this. I’m sure there is a smarter solution so I was hoping the brains on the forums might be able to help out?

  • #2 / May 29, 2011 10:06am

    Greg Salt

    3988 posts

    Hi Poccuo,

    I’m afraid that I don’t understand what it is that you are trying to do. What is an EMS? The PHP function htmlspecialchars is used to escape output to prevent code from executing so I’m not clear that might achieve on a template. Please clarify what is supposed to be happening here.

    Cheers

    Greg

  • #3 / May 29, 2011 2:26pm

    Poccuo

    22 posts

    Hi Greg, thanks for replying.

    An EMS is an Email Marketing Software (e.g. MailChimp or Campaign Monitor). I want the client to be able to copy/paste the HTML needed for an HTML email Blast. So I need the template to output the HTML in a way that a web browser won’t try to render it as a web page. I want my client to be able to copy/paste the HTML code. This is where the htmlspecialchars comes in. 

    The problem seems to be that EE parses the embed code nearly last and certainly after the PHP even when the template is set to “output”

    One solution would be to not use embed code but as the EE/HTML code is rather lengthy I like using templates to keep the code clean and easy to manage for myself and future developers on the project. So I was hoping maybe there was another way to hijack the parse order so that embed templates were to render before the PHP. I know that low variables can do this but I don’t want to work outside of the native EE template structure if at all possible.

    Thanks!

  • #4 / May 31, 2011 7:19am

    John Henry Donovan

    12339 posts

    Poccuo,

    In the past with CampaignMonitor I get a client to copy just the URL for that template and paste that in. CM sucks in the HTML for that page automatically.

    There are also add-ons available like Champagne

    Not that familiar with MailChimp

  • #5 / May 31, 2011 10:26am

    Poccuo

    22 posts

    John, this is a really good suggestion, but unfortunately my client’s CRM does not allow me to import eblasts via URL. I’ll also be using this approach to generate a plain text version of my email.

    It would really be helpful to know if it were possible to hijack the parse order to do what I want, if there are plugins that can help, or if I need to bark up a different tree.

    Thanks! I appreciate your help.
    mk

  • #6 / Jun 01, 2011 6:42am

    John Henry Donovan

    12339 posts

    Poccuo,

    This might be way off but can you just not wrap the code in tags? or put inside a textarea for selection if you want your client to copy/paste the code from EE?</p> <pre><code><textarea>{embed="/newsletters/html/"}</textarea>

    <code>{embed="/newsletters/html/"}
    </code>
    <pre>{embed="/newsletters/html/"}</pre><p>
    </pre>

  • #7 / Jun 01, 2011 12:45pm

    Poccuo

    22 posts

    These are good solutions, and things that I’ve tried. Unfortunately the embed code has the DOCTYPE / HTML tags in there so the page renders reguardless of the <code> / <pre> tags. I suppose I could pre-cleanse the HTML/DOCTYPE tags in the template (using lt’s and gt’s instead of <‘s and >‘s) but the template is also being used to serve up the live HTML version of the site so it wouldn’t be able to do double duty and I unnecessarily end up breaking a good DRY approach.

    I appreciate the alternative suggestions to my questions, and by all means keep them coming, but I’m getting the feeling that my inquiry into overriding parse order is either impossible or perhaps overly complex? something like that?

  • #8 / Jun 02, 2011 10:59am

    Kevin Smith

    4784 posts

    Hey Poccuo—

    Right, there’s not a way to alter parse order to get the template rendering engine to do what you want it to do here. The next route that I would take would be to look into developing a plugin that emulates the embed function and outputs through ‘htmlspecialchars’. I’m not positive that it’s possible, but I can’t think of a reason that wouldn’t work off the top of my head. And it would essentially be avoiding the problem with parse order because it would all happen within the plugin’s PHP file, so you’d be at the mercy of PHP’s parse order (which is more straight-forward) rather than EE’s parse order.

    Kevin

  • #9 / Jun 02, 2011 11:00am

    Kevin Smith

    4784 posts

    Also, just for reference, Low’s Parse Order PDF is a brilliant resource that I keep tacked on the bulletin board next to my desk. I reference it every day.

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

ExpressionEngine News!

#eecms, #events, #releases