0

This is a wordpress plugin I've used Backbone Marionette to build the back-end. The problem is that the template code (html and javascript) its being execute as php.

Fatal error: Call to undefined function substring() in ../main-menu.php on line 304

    <script type="text/template" id="amazon-result-item-view">
      <p class="small-text">
      <a href="<%= url %>" target="_blank" >
      <%= name.substring(0,30) %>...    //getting the php error at this line
      </a></p>

      <img width="100" src="<%= image_url %>" />
      <button data-product-index="<%= cid %>"
       class="tiny add-amazon-product">
      Add product</button>
    </script>

This is from a plugin that is working in several other WP sites my guess is that this one is parsing anything wrap by this <%= %> as php but not sure why...

nmos
  • 146
  • 1
  • 8
  • 2
    Maybe try using `_.templateSettings` to set a different escape syntax? Example at http://underscorejs.org/#template – ivarni Aug 10 '15 at 04:47

2 Answers2

0

As @ivarni mentioned you are able to change what delimiters underscore uses to interpolate values. For example you can pass the following regex to underscore to switch the delimiters to mustache style delimiters which should work in your case.

 _.templateSettings = {
       evaluate: /\{\[([\s\S]+?)\]\}/g,
       interpolate: /\{\{([\s\S]+?)\}\}/g, 
       escape: /\{\{-([\s\S]+?)\}\}/g
 };

You would then modify your template to something like this

  <script type="text/template" id="amazon-result-item-view">
      <p class="small-text">
      <a href="{{ url }}" target="_blank" >
      {[ name.substring(0,30) ]}...
      </a></p>

      <img width="100" src="{{ image_url }}" />
      <button data-product-index="{{ cid }}"
       class="tiny add-amazon-product">
      Add product</button>
    </script>
Community
  • 1
  • 1
Jack
  • 10,943
  • 13
  • 50
  • 65
0

You're using JSP syntax <%= %> instead of php syntax {[ whatever ]}. In this case, your 4th line should be like this:

{[ name.substring(0,30) ]}
Barett
  • 5,826
  • 6
  • 51
  • 55
ApuchYz
  • 3
  • 2