@AquaL1te, Thanks for the more concrete information. The generated HTML made me dig some further…
- The fact that
base_url
is empty doesn’t sound an alarm. When Grav is installed in the root of the domain,base_url
is expected to return an empty string. - However, “empty” can mean two things,
- The variable contains an empty string
- The variable does not exist in which case Twig happily ignores the output without throwing an error.
Only a{{ dump(variable) }}
will show a NULL value in Clockwork when the variable does not exist.
Hint: Install Clockwork
- The fact that
base_url_absolute
does not return anything IS worrying. It should always return a value.
This means the variable does not exist.
Because if this, I did some research…
-
Grav code: All variables that are available in ‘normal’ page templates, are being passed to template data.html.twig, when creating the thankyou page and email
-
However, according to Twig:
But as with PHP functions, macros don’t have access to the current template variables.
-
According to Twig again:
Tip: You can pass the whole context as an argument by using the special
_context
variable.
Solution:
- Pass the context into the macro, by altering the top and bottom line in data.html.twig as follows:
{% macro render_field(form, fields, scope, context) %} ... {{ macro.render_field(form, form.fields, '', _context) }}
- Access the variables using
context
, like:{% set privacy_url = context.base_url_absolute ~ '/privacy-verklaring' %}
Final plee: Provide accurate and factual information instead of “it doesn’t work”