accessing and setting variable in different blocks

ivopisarovic
Member | 5
+
0
-

Hello,
is it possible to set a latte variable and access its value in another block? Thanks you for advices.

{var $lastId=-1}

{block content}
...
{foreach $items as $item}
         ...
         {var $lastId=$item->id_messages}
{/foreach}
...
{/block}

{block scripts}
{include parent}
 <script type="text/javascript">
     var messages=new Messages({$lastId});
     messages.startRefreshing();
</script>
{/block}
Felix
Nette Core | 880
+
0
-

Yes it is possible. Your code snippet should works, doesn't it?

Comments

ivopisarovic:

No, it writes default value –1 down in the script.

4 years ago