1

It seems that when calling a CSS or JS file include, if the path contains {{ siteUrl }} it outputs {{ siteUrl }} in the html that is generated.

Like so; <link rel="stylesheet" type="text/css" href="{{ siteUrl }}css/styles.css"/>

Which should be (for example); <link rel="stylesheet" type="text/css" href="http://site.url/dev/css/styles.css"/>

Anything I'm missing here?

  • never had that happening to me, are you sure you don't have quotes around your siteUrl so it's just a string? like this: {{'siteUrl'}}? Either way, I don't it's necessary to add your full url to your assets paths. You can just point to them like href="/css/styles.css" – Jan_dh Jan 29 '17 at 1:03
  • Can you provide the code you use for includeCssFile and includeJsFile? – Aaron Berkowitz Jan 29 '17 at 18:10
  • This is the code; {% includeCssFile "{{ siteUrl }}css/modul.min.css" %} and {% includeJsFile "{{ siteUrl }}js/ui.min.js" %} – Anders Jan 30 '17 at 4:44
3

When you want to output Twig variables inside another Twig tag, you shouldn't include the braces around the variable.

So this:

{% includeCssFile "{{ siteUrl }}css/modul.min.css" %}
{% includeJsFile "{{ siteUrl }}js/ui.min.js" %}

Should be this:

{% includeCssFile siteUrl ~ "css/modul.min.css" %}
{% includeJsFile siteUrl ~ "js/ui.min.js" %}

These examples use the concatenation operator (~) to join the value held in the siteUrl variable to the string holding the path to the CSS or JS file to be included.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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