How to use scores / macros Nunjucks / includes metals in place?

I am having trouble reusing the template code in my markup files. For example, I would like to use the embed code for vimeo links and just pass the vimeo id to the call.

One example macro:

{% macro vimeoEmbed(id) %}
  <iframe src="https://player.vimeo.com/video/{{ id }}?title=0&byline=0&portrait=0" width="300" height="169" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
{% endmacro %}

Used as follows:

{{ vimeoEmbed(120394634) }}

This works if I define the macro in the markdown file directly. But, of course, I would like to have a global macro file to simplify maintenance.

I tried using Nunjucks {% import "macros.njk" as macros %}. macros.njkwill contain a macro vimeoEmbed.
But unfortunately, I keep getting Error: template names must be a string: undefined.

As an alternative, I tried to use {% include "vimeoEmbed.njk" %}, but I get the same Error: template names must be a string: undefined.


metalsmith-in-place, Nujucks 'include import metalsmith-layouts.

Nunjucks. !

+4
1

.

, metalsmith-in-place metalsmith-markdown. Markdown , , {{ "some string" }} {{ &quot;some string&quot; }}. , Markdown.

metalsmith-in-place 2.0.0-beta.1. JSTransformer, . Nunjucks, , issue Nujucks , Nunjucks . , , .

+2

Source: https://habr.com/ru/post/1651400/


All Articles