Current template:
<if test="Array.isArray(data.author) and data.author.length ne 1">
<if test="data.author.length == 1">
<dc:creator id="creator">${data.author}</dc:creator>
<meta refines="#creator" property="role" scheme="marc:relators">aut</meta>
</if>
<else>
<for each="author in data.author" status-var="loop">
<dc:creator id="creator${loop.getIndex()+1}">${author}</dc:creator>
<meta refines="#creator${loop.getIndex()+1}" property="role" scheme="marc:relators">aut</meta>
<meta refines="#creator${loop.getIndex()+1}" property="display-seq">${loop.getIndex()+1}</meta>
</for>
</else>
</if>
<else>
author is not array.
</else>
This object is being passed into the template:
{author: ['Author One', 'Author Two', 'Author Two', 'Author Two']}
Output:
<dc:creator id="creator1">Author One</dc:creator><meta refines="#creator1" property="role" scheme="marc:relators">aut <meta refines="#creator1" property="display-seq">1<dc:creator id="creator2">Author Two</dc:creator><meta refines="#creator2" property="role" scheme="marc:relators">aut <meta refines="#creator2" property="display-seq">2<dc:creator id="creator3">Author Two</dc:creator><meta refines="#creator3" property="role" scheme="marc:relators">aut <meta refines="#creator3" property="display-seq">3<dc:creator id="creator4">Author Two</dc:creator><meta refines="#creator4" property="role" scheme="marc:relators">aut <meta refines="#creator4" property="display-seq">4
The </meta> closing tags are not appearing, what is Marko doing?
Hey @grawlinson, it looks like you are expecting well-formed XML as output (not HTML). is that correct? The <meta> tag happens to be defined by the HTML grammar as a self-closing/open-only tag. Marko defaults to HTML mode. If you want well-formed XML as output, then you should use the .marko.xml file extension which may not be documented :/ Please let me know if that works for you.
It completely slipped my mind that I was expecting XML, I'm quite used to template engines supporting both HTML and XML.
Changing the extension completely breaks the code (<if> and <for> tested so far, all breaking)
test.marko.xml:1
(function (exports, require, module, __filename, __dirname) { <if test="Array.isArray(data.author) and data.author.length ne 1">
^
SyntaxError: Unexpected token <
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/george/coding/marko-playground/index.js:8:16)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
Hey @grawlinson, you need to install the Node.js require extension for .marko.xml by doing the following:
require('marko/node-require').install({ extension: '.marko.xml' });
Without that line, Node.js is trying to load your .marko.xml file as a JavaScript module. Please let me know if that solves your problem or if you are still facing issues.
Bump for those who still faces this problem...
For me things start to work when I do
require('marko/node-require').install({ extension: '.xml' })
My guess is that internally require('some.marko.xml') looks for loader associated with '.xml', which is more in line with require('path').extname('some.marko.xml')
marko/hot-reload.
Most helpful comment
Hey @grawlinson, you need to install the Node.js require extension for
.marko.xmlby doing the following:Without that line, Node.js is trying to load your
.marko.xmlfile as a JavaScript module. Please let me know if that solves your problem or if you are still facing issues.