phphtml-emailposthtml

inserting ignored php code within Maizzle components


I am working on a project using the Maizzle html-email framework that needs to have some php code embedded (but ignored) within the final production build file so that it can get later executed at runtime. Essentially I just want Maizzle to ignore the blocks of php code during the build process.

simplified code to ignore from component file that is included in main template file with the <component src="compname.html"></component> tag.

...
<p>News for the Week of <rawcode class="rawcode"><?php echo $start_date ?> to <?php echo $end_date ?> from the following categories: <?php echo $cat01, $cat02, $cat03, $cat04 ?></rawcode></p>
...

code from config.production.js file

 posthtml: {
    plugins: [require('posthtml-custom-elements')()],
    options: {
      directives: [{ name: '?php', start: '<', end: '>' }],
    },
    expressions: {
      ignoredTag: 'rawcode'
    },
  },

As long as the php code is directly within the main template file, I have been able to get this to work using the Raw tag to skip over expression parsing, as well as adding the posthtml-custom-elements directive to my config file using the example shown in the Maizzle documentation to skip ignore the php code.

The Problem: However, I cannot get this to work if the php code is within a component file that I have included within my template file. Any php code within a component file gets completely stripped out after running "maizzle production build".

I am hoping someone can help with a solution, or if this is just a limitation of how Maizzle works.


Solution

  • Update

    This has been fixed in Maizzle v3.1.6.


    Mark, I think this might be an issue with the posthtml-modules plugin that we're using for the Components functionality in Maizzle.

    Specifically, its processWithPostHtml method doesn't pass any options to PostHTML rendering, so your posthtml config in Maizzle's config.js isn't inherited/passed down. That would explain why it works outside components.

    I'll need to confirm this with the PostHTML team; hopefully it's an easy fix in posthtml-modules and we can pass the user's PostHTML options from the Maizzle config to it, automatically.

    I've created an issue in Maizzle for it and will update my response in both places once we find a solution 👍

    P.S.: you don't need the <raw> tag or the posthtml-custom-elements plugin in order to render PHP code, you can safely remove those if not using them for other purposes.