Closed xiusin closed 4 years ago
With the first line, {{block art(row=10, ids="", sort="") }}
, you defined a block named art
with three arguments (and a default values). That's why the next line, {{ range k,v := art(row, ids, sort) }}
, can't work: it tries to call a function called art
(that does not exist) with the parameters passed into the block when it's used later. And you don't even pass in arguments to the block when you yield it later in your second code block.
Instead, try doing something like that, using a map to pass the actual values you range over into the block:
file1.jet:
{{ block pair(k, v) }}
<div>{{k}} => {{v}}</div>
{{ end }}
{{ block art(kvPairs) }}
{{ range k, v := kvPairs }}
{{ yield pair(k, v) }}
{{ end }}
{{ end }}
file2.jet:
{{ import "./file1.jet" }}
{{ pairs := map(1, 2, 3, 4) }}
{{ yield art(pairs) }}
You have to import the blocks from another file so they aren't rendered immediately (https://github.com/CloudyKit/jet/wiki/3.-Jet-template-syntax#simple-example).
I don't think what you want to do, providing a template to execute as the yield content, is possible.
@sauerbraten thinks, i got it.
Sorry for my English, I hope you can understand it
I want to use the value of range with content
eg:
output:
Like this.