Twig error after update with concat tilde

After updating to 1.4 (Although It could be a change in another plugin since this site was ~6m old and I did a bulk update to everything) … I get " Twig_Error_Syntax - Unexpected character “&” …" in the following markdown where I concat the string (~) in the twig. If I remove the tilde ~ it passes over to the next time I’ve done this.


title: footer2
process:
twig: true

MENU


Home
[Gallery]({{home_url ~ “/gallery” }})

Can anyone suggest what’s going wrong?
thanks,

Hugh

It looks fine to me. It’s a strange error I haven’t seen myself.

What is the value of home_url? What happens when you substitute home_url for a literal string e.g. “/siteroot”.

A couple of (unsatisfying) workarounds:

  • ({{ home_url }}/gallery) should provide the same result
  • do you have a good reason to think the home URL will not be the server root? Unless you do, simply hardcoding [Gallery](/gallery) will be fine, no need to involve Twig :slight_smile:

Interested to find out the cause here. Good luck!

Might might have to set twig_first: true in config, but I would prefer either of hughbris’ workarounds, especially the latter one. If you are just referring to domain.tld/gallery, you want to use native methods like /, ./ or ../ to determine paths.

Thanks for the feedback. I have used your suggestions to work around the issue, but I have also been able to reproduce the problem in a clean install of v1.4.1.

In the MD file with process: twig: true

This {{home_url}} or {{home_url}}/blah or even {{home_url ~ "\blah"}} work as expected.

However if I put the twig in a link it fails.

On my devel setup (WinOS, WAMP) installed under /grav14 I get these results:

[home_url]({{home_url}}) => http://127.0.0.01/grav14

[home_url/blah]({{home_url}}/blah) => http://127.0.0.1/grav14/home//grav14/blah

and

[home_url-tilde-blah]({{home_url ~ "/blah"}}) … i.e. with the tilde it crashes as originally reported.

Just repeating, this is a clear install of v1.4.1.

Is this a bug? Or something has changed in v1.4? Twig worked OK in the links before I upgraded.

It does seem like a bug in parsing and quite possibly in Grav, so please log an issue with instructions to reproduce if you can. Could you try [home_url-tilde-blah]({{(home_url ~ "/blah")}}) (extra parentheses inside Twig)?, though even if that works, I think there’s a bug here.