0

Is it possible to use the macros defined in DefaultScreenMacros.hmlt.ftl directly in others ftl? I have made a custom component in Moqui, and I used ftls for templating, I wanted to use <@text\-line> to insert an autocomplete field into an ftl but it doesn't seem to work.

I suspect that the ftls doesn't automatically include DefaultScreenMacros.hmlt.ftl , I tried to include it manually like this:

<#include "classpath://moqui/runtime/template/screen-macro/DefaultScreenMacros.html.ftl"/>

but still no joy. Any clues?

@ddekany You are right, and I figure that one out. That's one problem and is on the moqui part. The path is correct but I am unsure if it is on the classpath. Anyway if I add all the macros in the flt file (or if I put a local valid classpath) then I when I call them like <@someMacro> they will fail because those macros are made to process xml not ftls. For example this macro:

<#macro container>
    <#assign divId><@nodeId .node/></#assign>
    <${.node["@type"]!"div"}<#if divId?has_content> id="${divId}"</#if><#if .node["@style"]?has_content> class="${ec.resource.expand(.node["@style"], "")}"</#if>>
    <#recurse>
    </${.node["@type"]!"div"}>
</#macro>

Will process xml like:

<container id="test">
</container>

And produce this:

<div id="test">
</div>

Bu if I call from within a ftl containing that macro like this:

<@container id="test">
</@container>

I get:

[Template Error: Macro "container" has no parameter with name "id". ---- FTL stack trace ("~" means nesting-related): - Failed at: #macro container [in template ...

Is there a way to call it in the ftl without changing tha macro?

G. Medici
  • 3
  • 1
  • 3
  • Yes, macros defined in an `#include`-d file should work. What error message do you get? – ddekany Dec 15 '16 at 19:45
  • o.moqui.r.ClasspathResourceReference[m Could not find location [moqui/runtime/template/screen-macro/DefaultScreenMacros.html.ftl] on the classpath – G. Medici Dec 18 '16 at 10:13
  • I juts wanted to use the default macros in a ftl. Something like this: <@interpretXml> @> – G. Medici Dec 18 '16 at 10:17
  • The error message says that it can't find that ftl file at all, so your problem has nothing to do with macros. Your question should be why the template file is not found. Is the paths shown in the error message correct? – ddekany Dec 20 '16 at 23:57

0 Answers0