Support » Plugin: Genesis Custom Blocks » The ” character (ACSII #34) is getting modified when displayed on the site

  • Resolved neutrall

    (@neutrall)


    Hi, I am creating a block with a text filed that will need to be parsed. the original text entered is a list separated with the “|” character.
    The template code is simple, it will explode the list and rebuild it in the form of HTML UL/LI and place it inside a HTML data attribute:

    <?php 
    // Define the tooltip content if set
    $content = trim(block_field( 'popup-content', false));
    if ($content != "") {
        
        $contentArray = explode('|', $content);
        
        $tooltipContent = '<ul>';
        foreach ($contentArray as $contentli) {
           $tooltipContent .= '<li>'.$contentli.'</li>';
        }
        $tooltipContent .= '</ul>';
        
    }?>
    <div class="icons <?php block_field( 'icone'); ?>"></div>
    <?php block_field( 'text'); ?>
    <span class="has-tip" tooltip-title="<?php block_field( 'popup-title'); ?>" tooltip-content="<?=$tooltipContent ?>"><svg ... ><path ...></path></svg>
    </span>

    Every time this code is executed, the last ” in the following code tooltip-content="<?=$tooltipContent ?>">< is getting replaced by &nbsp;».

    Therefore, the block is not being rendered properly. It will simply output the raw text field block_field( 'popup-content'), the last ” is not being changed.

    I can replicate the problem simply by placing the following HTML code in the php template file:

    <div tooltip-content="<ul><li>test</li><li>test</li></ul>"></div>

    • This topic was modified 2 months ago by neutrall.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter neutrall

    (@neutrall)

    With further testing, I’ve noticed that the problem appears only when the “>” character is present inside the HTML attribute.

    Plugin Contributor Ryan Kienstra

    (@ryankienstra)

    Hi @neutrall,
    Thanks for letting us know.

    That’s probably happening because block_field() calls wp_kses_post().

    Could you use block_value() and then echo the result?

    Like:

    
    $icone = block_value( 'icone');
    ?>
    <div class="icons <?php echo $icone ?>"></div>
    
    Plugin Contributor Ryan Kienstra

    (@ryankienstra)

    Ah, that probably won’t work. Thinking…

    Plugin Contributor Ryan Kienstra

    (@ryankienstra)

    Have you tried this?

    
    esc_attr( $tooltipContent )
    

    It’s a little unconventional having unescaped markup inside an attribute.

    For example, this is what the template pasted above it looks like in Chrome (without escaping $tooltipContent):
    https://cldup.com/ziSS9EJLN7.png

    What is the expected output inside tooltip-content ?

    Thread Starter neutrall

    (@neutrall)

    Thank you, this work around worked perfectly, I just feel a little silly for not trying it before!

    The output expected is and HTML unordered list that will be used with mouse hover events to create a tooltip popup.

    Plugin Contributor Ryan Kienstra

    (@ryankienstra)

    All good, I feel silly most days for missing things 😉

    Plugin Contributor Ryan Kienstra

    (@ryankienstra)

    Would you be open to reviewing us?
    https://wordpress.org/support/plugin/genesis-custom-blocks/reviews/

    Thanks, that’d help a lot.

    Thread Starter neutrall

    (@neutrall)

    I’ve left the review, thank again and have a great day!

    (You may close this case)

    Plugin Contributor Ryan Kienstra

    (@ryankienstra)

    Hi @neutrall,
    Thanks a lot for your review! Have a great day also!

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.