Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access variables of an outer scope from within an {{each}} block of a jQuery tmpl template?

For example, in this code:

<div id="user_collection_requests-${id} table-cell" class="user_collection_requests">
        {{if requests}}
            {{each(i, user) requests}}
                <div id="user_collection_request-${id}-${user.id}" ...
            {{/each}}
        {{/if}}
    </div>

The first ${id} prints the outer object's id attribute, but the second ${id} prints the same as ${user.id}. I want to grab the outer scope's id from within the {{each}} block.

Is this possible? Or do I have to be sure to name the variables so that a collision like this will not occur?

like image 790
Colin Sullivan Avatar asked Nov 26 '22 17:11

Colin Sullivan


1 Answers

You can declare a variable outside your {{each}} block

${( $data.localVariable = $id ),''}

and access it inside later

${localVariable}
like image 151
zero7 Avatar answered Jan 05 '23 01:01

zero7