Question

I've been using jsviews to link and render some templates. In one of my template, I have the following {{if}} condition.

<script id="listTmpl" type="text/x-jsrender">    
  {{if content_type.indexof('IMG_') >= 0 }}
    <span class="content-img-preview" data-src={{:distURL}}></span>
  {{else}}
    ''
  {{/if}}
</script>

Where content_type is a string that can can be like 'IMG_201_345'. However, the indexof() function does not work. How else can I check if the string contains the pattern 'IMG_' using the {{if}} condition?

Was it helpful?

Solution

If I use indexof my code return:

Error: Object IMG_201_345 has no method 'indexof'.

by using indexOf is working fine.

Demo: http://jsfiddle.net/IrvinDominin/MG3nL/

OTHER TIPS

On line

{{if content_type.indexof('IMG_') >= 0 }}

function name should be changed to correct in this way:

{{if content_type.indexOf('IMG_') >= 0 }}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top