The templates are read into memory. See functions_email line 551 (in Github latest). You can perform arbitrary manipulations at that point.
That Software Guy. My Store: Zen Cart Modifications
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.
I'm suggesting a core change to do this. It's a useful fix, and this is how I'd implement it. But this is just a suggestion -let's see what Simon comes up with before we debug it. :)
That Software Guy. My Store: Zen Cart Modifications
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.
Hope you're not expecting too much!
Using your str_replace idea, and to temporarily avoid the complication of CR/LF I put the code in email_template_direct_email.html on one line like so:
in a direct email this gives html code:Code:<div class="extra-info">$EXTRA_INFO</div>
so I thought that in functions_email.php adding line #539 would make sense:Code:<div class="extra-info"></div>
no luck nothing is replaced. Although if I just use:Code://strip linebreaks and tabs out of the template // $file_holder = str_replace(array("\r\n", "\n", "\r", "\t"), '', $file_holder); $file_holder = str_replace(array("\t"), ' ', $file_holder); $file_holder = str_replace('<div class="extra-info"></div>', '', $file_holder);
then <div class="extra-info"> IS replaced. So it 'thinks' there is still something inside the div tags? I wondered whether the str_replace should be later in the code.Code://strip linebreaks and tabs out of the template // $file_holder = str_replace(array("\r\n", "\n", "\r", "\t"), '', $file_holder); $file_holder = str_replace(array("\t"), ' ', $file_holder); $file_holder = str_replace('<div class="extra-info">', '', $file_holder);
That's as far as I got.
Simon
obviously removes that entire line from the template. So maybe there needs to be a condition where it is only removed if $extra_info is empty. TriedCode:$file_holder = str_replace('<div class="extra-info">$EXTRA_INFO</div>', '', $file_holder);
no joy.Code:if (empty($extra_info)) { $file_holder = str_replace('<div class="extra-info">$EXTRA_INFO</div>', '', $file_holder); }
Simon
How about something like
That way, if either the 'EXTRA_INFO' block is not present or contains only 'whitespace' characters, the entire 'extra-info' div will be removed from the email template.Code:if (empty($block['EXTRA_INFO']) || empty(trim($block['EXTRA_INFO']))) { $file_holder = preg_replace('/<div class="extra-info">\s?\$EXTRA_INFO\s?<\/div>', '', $file_holder); }
+1. Nice.
That Software Guy. My Store: Zen Cart Modifications
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.
Previously received HTML emails are now in text-only format. Error logs pointed me in the direction of a missing '/' like so:
Your code works as intended. Thanks.Code:if (empty($block['EXTRA_INFO']) || empty(trim($block['EXTRA_INFO']))) { $file_holder = preg_replace('/<div class="extra-info">\s?\$EXTRA_INFO\s?<\/div>/', '', $file_holder); }
Simon
Thanks for the update; those pesky delimiters! FWIW, I use https://rubular.com/ to help me with those regular expressions.
Bookmarks