I tried to add a repeat refinement to build-markup function using the previous answer: http://stackoverflow.com/questions/2775701/how-to-bind-to-foreach-context
build-markup: func [
{Return markup text replacing <%tags%> with their evaluated results.}
content [string! file! url!]
/repeat block-fields block-values
/quiet "Do not show errors in the output."
/local out eval value
][
either not repeat [
content: either string? content [copy content] [read content]
out: make string! 126
eval: func [val /local tmp] [
either error? set/any 'tmp try [do val] [
if not quiet [
tmp: disarm :tmp
append out reform ["***ERROR" tmp/id "in:" val]
]
] [
if not unset? get/any 'tmp [append out :tmp]
]
]
parse/all content [
any [
end break
| "<%" [copy value to "%>" 2 skip | copy value to end] (eval value)
| copy value [to "<%" | to end] (append out value)
]
]
][
probe :block-fields
foreach :block-fields block-values [
print get pick :block-fields 1
print get pick :block-fields 2
]
]
out
]
c: [a b]
template: "<%a%> <%b%>"
build-markup/repeat template :c [1 2 3 4]
Output is not what I want:
>> c: [a b]
== [a b]
>> template: "<%a%> <%b%>"
== "<%a%> <%b%>"
>> build-markup/repeat template :c [1 2 3 4]
[a b]
1
1 a b
1
1 a b
whereas I would have expected
1
2
3
4
So how should I correct ?