Auto add style and border attributes to img tag when sending an email

Notice: This thread is very old.
lucien144
Member | 10
+
0
-

Hi guys,
I'm sending emails from Nette application where the email body is a Latte template. I want to automatically add attributes border="0" and style="display: block;" to all IMG tags in the email's body.

Right now, if I create a new template, I have to add these manually but I'd like to find more comfortable way of doing this. Something like using custom n:macro or so… So next time, if I prepare another EDM to be sent, I don't have to have in my mind this → https://litmus.com/…otmail-yahoo.

Thanks.

Last edited by lucien144 (2015-03-17 16:01)

lucien144
Member | 10
+
0
-

Ok, the best solution I could find so far using the custom macro. Something like this

** PHP **

class CustomMacros extends Latte\Macros\MacroSet
{

    public static function install(Latte\Compiler $compiler)
    {
        $set = new static($compiler);
        $set->addMacro('edmimg', array($set, 'edmImg'));
    }

    public function edmImg(MacroNode $node, PhpWriter $writer)
    {
        return $writer->write('' .

                                'echo "<img border=\"0\" style=\"display: block;\" ";'.
                                'foreach(%node.array as $key => $value)'.
                                '   { '.
                                        'if ($key == "src") echo $key . "=\"" . $baseUrl.$value . "\""; '.
                                        'else echo $key . "=\"" . $value . "\""; '.
                                    '}'.
                                'echo ">";'

                            );
    }

}

** Used in template **

{edmimg src => "/images/edm/footer_01.png", width => "41", height => "90", alt => "Logo"}

** Generated HTML **

<img border="0" style="display: block" src="http://www.base.url/images/edm/footer_01.png" width="41" height="90" alt="Logo">