BorisMoore / jsrender

A lightweight, powerful and highly extensible templating engine. In the browser or on Node.js, with or without jQuery.
http://www.jsviews.com
MIT License
2.67k stars 339 forks source link

Get an error t is not a function when adding if block #372

Closed financialswprogrammer closed 1 year ago

financialswprogrammer commented 1 year ago

I have a template that works fine, but when I added the {{if}} block I get an error that t is not a function (t is a variable in the top loops). Note if I just use the if block it renders, or if I just use the rating block it renders but not with both. Any ideas what I might be doing wrong here or is this a bug?

Thank you

<script id="infoTmpl" type="text/x-jsrender">
    <div class="infoContainer">
        <div class="propertyImage">
            <img src="{{>Image}}" width="100%" />
        </div>
        <div class="propertyInfo">
            <div class="info-rating">
                {{* var t = 0; }}
                {{*  while (t < data.Star) { }}
                <i class="fa-solid fa-star"></i>
                {{*    t++;  } }}
                {{*  while (t < 5) { }}
                <i class="fa-solid fa-star" style="color: lightgray"></i>
                {{*    t++;  } }}
            </div>
            {{if Rating}}
            <div class="hotel-rating-wrapper">
                <div class="hotel-rating-value"><span><b>{{>Rating}}</b> / 5</span></div>
                <span class="hotel-guest-rating-label"> Guest rating</span>
            </div>
            {{/if}}
            <h4 class="info-header">{{>Name}}</h4>
            <div class="info-address">{{>Address}}</div>
            <a class="info-price" href="#" onclick="findRooms('{{>Id}}')">${{:Price.toFixed(0)}} and up</a>
        </div>
    </div>
</script>
financialswprogrammer commented 1 year ago

Strange, I resolved by renaming the variable "t" to "index" and it works now.