2

I'm trying to upgrade my website to Craft 3, so I've imported all template files and installed the necessary plugins, but I can't deal with one error.

I've got a template named _layout.twig, and the first line used to import macros from other file called _helpers.twig. For some reason this doesn't work on Craft 3 - I checked in Twig documentation and it seems that everything is correct. I reviewed the changes in Craft 3 but didn't find anything related there. Running Craft 3.3 with Twig 2.11.3.

_layout.twig

{% import '_common/_helpers' as helpers %}
{{ helpers }}

Error

Twig Runtime Error – Twig\Error\RuntimeError Variable "helpers" does not exist.

in /craft3/templates/_layout.twig at line 2

Any ideas what can be the issue here?

1 Answer 1

4

I think you need to reference a macro name inside of your _common/_helpers file.

For example:

{{ helpers.input('username') }}

That would output a macro called input:

{% macro input(name, value, type = "text", size = 20) %}
    <input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}" />
{% endmacro %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.