Search code examples
javascriptjquerytemplatesjqote

Accessing jQuery itself, and other globals from within jQote2 template


Using jQote, my templates compile properly into lamdas unless I use things like $.each(), or attempt to access other globals like my own environment variables accessed through _.* ... similar to how jQuery is accessed through $.*

My tags are setup to be <* *> ... I need to be able to do things like this:

<* $.each( this.scheduled, function( i, s ) { *>
    <a href="<*= _.base *>/.calendar/goto/<*= s.timestamp *>">
        <*= s.readable *>
    </a>
<* }) *>

Doing that for example gets me this error, for using $._ ... and if I change from $.each() to for() { } for example, then _.* triggers the same kind of error:

Expected an identifier but found 'out' instead

Looking at successfully compiled templates, out is the string that jQote2 is filling with a parsed template, populated with data. All I can really access is the this which contains my data.

How do I access global variables inside jQote2 templates without triggering this obscure error?


Solution

  • It was not a scope issue at all!

    After extensive digging, and validation of the code generated by jQote2, this is all it ended up being:

    <* $.each( this.scheduled, function( i, s ) { *>
        <a href="<*= _.base *>/.calendar/goto/<*= s.timestamp *>">
            <*= s.readable *>
        </a>
    <* }); *>
    

    Let's zoom in on the one character that made all the difference: <* }); *>

    Missing SEMI-COLON! Being sure to completely close code blocks seems extremely important with the level of compression applied to templates, once they are compiled.