Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#37265 closed defect (bug) (invalid)

underscorejs Escaping Issues

Reported by: casben79's profile casben79 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.5.3
Component: General Keywords:
Focuses: Cc:

Description

I am attempting to customise a WooCommerce single variation template which uses the WP underscore.js setup.

The following is throwing a JS error: Uncaught SyntaxError: Unexpected token ) in underscores.min.js

<div class="attributes">

    {{{ _.each( data.variation.attribute_data, function(element, index, list) { }}}

        <span class="test">TEST</span>

    {{{ }); }}}

</div>

If I change it to the following it works fine, I just need to escape into HTML for the templating.

<div class="attributes">

    {{{ _.each( data.variation.attribute_data, function(element, index, list) { 
        
        console.log( element );
            
    }); }}}

</div>

Change History (1)

#1 @adamsilverstein
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hello @casben79 thanks for the bug report. I don't think this is a WordPress core issue, and this trac is for reporting bugs in WordPress core.

I think you are using {{{ incorrectly, this is for unescaped output. if you want to run raw JS, i think you want <% %> for straight underscore (or are you using wp.template?).

Closing this ticket as invalid, feel free to hit me up in Slack and I may be able to help you troubleshoot.

Note: See TracTickets for help on using tickets.