• Resolved krabbe

    (@krabbe)


    I want to share my solution to make the use of template conditional.

    In my use case I needed a different header image for each newsletter. And I want all the other mails sent by wordpress or plugins to use the configured settings of “Email Templates” plugin.

    I copied the plugins template folder into my theme, put this in functions.php:

    add_filter('mailtpl/customizer_template', 'custom_mail_template');
    function custom_mail_template() {
      return get_stylesheet_directory() . "/mail-templates/default.php";
    };

    In default.php I can get $_POST variable to find out, if the email is a newsletter and load different templates.

    $settings = Mailtpl::opts();
    $args = $_POST;
    if ( ! isset( $_POST ) ) {
      $type = 'default';
    } elseif ( ! isset( $_POST["es_templ_heading"] ) ) {
      $type = 'admin';
    } else {
      $type = 'newsletter';
      $newsletter_id = $_POST["es_templ_heading"];
      $settings['newsletter_id'] = (int)$newsletter_id;
    }
    
    if ( $type == 'newsletter' ) {
      include_once( 'partials/header_newsletter.php' );
    } else {
      include_once( 'partials/header.php' );
    }
    include_once( 'partials/email-content.php');
    include_once( 'partials/footer.php' );

    I get the post id from “es_templ_heading” and put that in $settings, to be able to load the newsletter header from a custom field in newsletter post.

    Maybe this solution can help others… and thanks for the plugin!

    Krabbe

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Conditional Logic for Email Templates’ is closed to new replies.