koala-framework / koala-framework

Framework and CMS based on Zend Framework and ExtJS
http://www.koala-framework.org/
BSD 2-Clause "Simplified" License
62 stars 39 forks source link

Duplicate and delete lines in Kwf_Mail_Template #594

Open Sogl opened 7 years ago

Sogl commented 7 years ago

Hi!

Duplicate lines

I have generated style from css mail framework:

<p style="-webkit-font-smoothing: subpixel-antialiased; Margin: 1em 0; color: #333333; font-
family: helvetica, arial; font-size: 14px; line-height: 20px; text-align: left;">Some text</p>

I can use it as Kwf_Mail_Template variable:

<p style="-webkit-font-smoothing: subpixel-antialiased; Margin: 1em 0; color: #333333; font-family:
helvetica, arial; font-size: 14px; line-height: 20px; text-align: left;"><?=$this->something?></p>

But I have different lines so I need to have final output using php loop:

<p style="-webkit-font-smoothing: subpixel-antialiased; Margin: 1em 0; color: #333333; font-family:
helvetica, arial; font-size: 14px; line-height: 20px; text-align: left;">Line 1</p>
<p style="-webkit-font-smoothing: subpixel-antialiased; Margin: 1em 0; color: #333333; font-family:
helvetica, arial; font-size: 14px; line-height: 20px; text-align: left;">Line 2</p>
<!-- etc -->

How to duplicate lines without putting html tags to my php content?

Delete lines

I have some buttons in mail that I want to delete/exclude using php conditions. How to delete parts from my .tpl file in php?

nsams commented 7 years ago

you could use someting like https://github.com/jjriv/emogrifier or the much simpler Kwc_Mail_HtmlParser.

you can integrate both by subclassing Kwf_Mail_Template and overriding _getHtmlMailContent

Sogl commented 7 years ago

you could use someting like https://github.com/jjriv/emogrifier

Do you mean something like this:

$html = '<html><h1>Hello world!</h1></html>';
$css = 'h1 {font-size: 32px;}';
$emogrifier = new \Pelago\Emogrifier($html, $css);

?

But how to insert template variables in loop (including txt.tpl template too)?

nsams commented 7 years ago

I think I didn't understand your question. I thought you want to avoid duplicating the p style attribute.

.tpl files are interpreted as real php files, you can use any <?php if for <?php foreach or whatever you need

Sogl commented 7 years ago

I mean that I want to use something like Twig loop functions in template: http://twig.sensiolabs.org/doc/2.x/tags/for.html

Also in Laravel Blade templates (Loops section): https://laravel.com/docs/5.4/blade#control-structures

Then I can send array to template for the loop to avoid using html/css in php.

nsams commented 7 years ago

That's how Zend_View_Template works (by default) - those .tpl files are php files and to create a loop simply use

<?php foreach ($this->foos as $foo) { ?>
    <?=$foo?>
<? } ?>
nsams commented 7 years ago

Twig templates are currently not supported by Kwf_Mail_Template, you could however use Twig to render a template and Kwf_Mail with setBodyHtml