Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23
  1. #11
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Hide empty div in emails

    Quote Originally Posted by swguy View Post
    Have you considered using `str_replace()` to remove the extra_info block if it's empty? That's how I would implement this change.
    The problem lies in the email template(s) themselves, so I don't see how str_replace could be used.

  2. #12
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,672
    Plugin Contributions
    123

    Default Re: Hide empty div in emails

    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.

  3. #13
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Hide empty div in emails

    Quote Originally Posted by swguy View Post
    The templates are read into memory. See functions_email line 551 (in Github latest). You can perform arbitrary manipulations at that point.
    Yes, but there are very few notifiers within those email-generating functions.

  4. #14
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,672
    Plugin Contributions
    123

    Default Re: Hide empty div in emails

    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.

  5. #15
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,238
    Plugin Contributions
    1

    Default Re: Hide empty div in emails

    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:

    Code:
    <div class="extra-info">$EXTRA_INFO</div>
    in a direct email this gives html code:

    Code:
    <div class="extra-info"></div>
    so I thought that in functions_email.php adding line #539 would make sense:

    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);
    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">', '', $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.

    That's as far as I got.
    Simon

  6. #16
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,238
    Plugin Contributions
    1

    Default Re: Hide empty div in emails

    Code:
    $file_holder = str_replace('<div class="extra-info">$EXTRA_INFO</div>', '', $file_holder);
    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. Tried

    Code:
    if (empty($extra_info)) {
    	$file_holder = str_replace('<div class="extra-info">$EXTRA_INFO</div>', '', $file_holder);
    }
    no joy.
    Simon

  7. #17
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Hide empty div in emails

    How about something like
    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);
    }
    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.

  8. #18
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,672
    Plugin Contributions
    123

    Default Re: Hide empty div in emails

    +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.

  9. #19
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,238
    Plugin Contributions
    1

    Default Re: Hide empty div in emails

    Quote Originally Posted by lat9 View Post
    How about something like
    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);
    }
    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.
    Previously received HTML emails are now in text-only format. Error logs pointed me in the direction of a missing '/' like so:

    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);
    }
    Your code works as intended. Thanks.
    Simon

  10. #20
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Hide empty div in emails

    Quote Originally Posted by simon1066 View Post
    Previously received HTML emails are now in text-only format. Error logs pointed me in the direction of a missing '/' like so:

    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);
    }
    Your code works as intended. Thanks.
    Thanks for the update; those pesky delimiters! FWIW, I use https://rubular.com/ to help me with those regular expressions.

 

 
Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Hide a <div> in JUST the home page..
    By DivaVocals in forum Templates, Stylesheets, Page Layout
    Replies: 29
    Last Post: 30 Sep 2014, 07:42 PM
  2. Checkout Confirmation Page - Radio Button to Hide Div
    By limelites in forum General Questions
    Replies: 0
    Last Post: 1 May 2012, 11:28 PM
  3. Why does my right div appear on Your Cart is Empty page?
    By datatv in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 16 Jul 2008, 07:05 PM
  4. HTML Emails - DIV vs. Tables
    By Radish in forum General Questions
    Replies: 0
    Last Post: 28 Sep 2006, 07:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR