Closed dzeroc closed 4 months ago
I think the example is wrong. Can you try changing menu_item.vto
to this?
{{ if item.data }}
<a href="{{ item.data.url }}">
{{ item.data.title }}
</a>
{{ else }}
<span>{{ item.slug }}</span>
{{ /if }}
<ul>
{{ for child of item.children }}
<li>
{{ include "templates/menu_item.vto" { item: child } }}
</li>
{{ /for }}
</ul>
(Rename the second item
to child
to avoid variable name conflict). Probably it's a bug in Vento.
It works! I imagined something like this, but I don't know enough about Vento. Thank you very much.
Could you please update the documentation?
Done! Thank you!
Version
2.1.0
Platform
Ubuntu 23.10, Deno 1.41
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
No error.
What do you see instead?
{{ include "./menu.vto" }}
{{ include "menu_item.vto" { item } }}
{{ for item of item.children }}
Caused by Error: Error in the template /_includes/menu.vto:4:7
{{ include "menu_item.vto" { item } }}
{{ for item of item.children }}
Caused by Error: Error in the template /_includes/menu_item.vto:10:3
{{ for item of item.children }}
Caused by ReferenceError: Cannot access 'item' before initialization at eval (eval at compile (https://deno.land/x/vento@v0.10.2/src/environment.ts:42:25),:27:41)
at Environment.run (https://deno.land/x/vento@v0.10.2/src/environment.ts:69:18)
at eventLoopTick (ext:core/01_core.js:153:7)
at async eval (eval at compile (https://deno.land/x/vento@v0.10.2/src/environment.ts:42:25), :14:19)
at async Environment.run (https://deno.land/x/vento@v0.10.2/src/environment.ts:69:12)
at async eval (eval at compile (https://deno.land/x/vento@v0.10.2/src/environment.ts:42:25), :11:19)
at async Environment.runString (https://deno.land/x/vento@v0.10.2/src/environment.ts:87:14)
at async VentoEngine.render (https://deno.land/x/lume@v2.1.0/plugins/vento.ts:94:20)
at async Renderer.render (https://deno.land/x/lume@v2.1.0/core/renderer.ts:216:19)
at async Renderer.#renderLayout (https://deno.land/x/lume@v2.1.0/core/renderer.ts:293:17)
Additional information
Am I doing something wrong? I just followed the official documentation.