Faizan Ali
Faizan Ali

Reputation: 1013

<# Syntax in Wordpress

I was just viewing source of a Wordpress Admin Screen and I noticed the <# kind of syntax. Please see the screenshot attached as well. I wanted to know what language or markup is that?enter image description here

Upvotes: 2

Views: 77

Answers (1)

vard
vard

Reputation: 4156

If you look into wp-includes/js/wp-util.js, you'll find the following function that parse those tags:

wp.template = _.memoize(function ( id ) {
    var compiled,
        /*
         * Underscore's default ERB-style templates are incompatible with PHP
         * when asp_tags is enabled, so WordPress uses Mustache-inspired templating syntax.
         *
         * @see trac ticket #22344.
         */
        options = {
            evaluate:    /<#([\s\S]+?)#>/g,
            interpolate: /\{\{\{([\s\S]+?)\}\}\}/g,
            escape:      /\{\{([^\}]+?)\}\}(?!\})/g,
            variable:    'data'
        };

    return function ( data ) {
        compiled = compiled || _.template( $( '#tmpl-' + id ).html(), null, options );
        return compiled( data );
    };
});

As the comment explain, they changed the template tag <% %> to Mustache tags in version 3.5 to avoid any conflict with asp tags.

Upvotes: 1

Related Questions