list - Freemarker: getting a Template with include (prefix) -
im trying following:
maintemplate.ftl
<root> <#list items item> <#include "custom_item.ftl"> [option 1] </#list> <#include "custom_item.ftl"> [option 2] </root>
custom_item.ftl
<root> <name>${name}</name> </root>
in files include [option 1], in others [option 2]. access ${name} variable have use 2 different ways:
- option 1: ${item.name} - option 2: ${name}
totally understandable, issue. how can make sure works? supplying prefix include same.
for example like:
maintemplate.ftl
<root> <#list items item> <#include "custom_item.ftl" prefix='item'> [option 1] </#list> <#include "custom_item.ftl"> [option 2] </root>
custom_item.ftl
<root> <# assign prefix = prefix?root> <name>${prefix.name}</name> </root>
which work. approach doesnt work, has solution work?
edit: answer included
maintemplate.ftl
<root> <#list listitems listitem> <#assign item = listitem> <#include "custom_item.ftl"> </#list> <#assign item = .data_model> <#include "custom_item.ftl"> </root>
custom_item.ftl
<root> <name>${item.name}</name> </root>
always use ${item.name}
. in case when data-model root item (is it?), can <#assign item = .data_model>
before #include
.
Comments
Post a Comment