Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Is there a way to use variables in Volt stylesheet_link and javascript_include commands?

I find myself doing the following because I have been unable to use variables in the stylesheet and javascript include commands. I would like to specify the base path once in a base controller (either empty string or 'http://localhost:8080/'). How do I do this? I know how to set it in the controller but I don't want to use assets, just a variable.

{% if resourceLoad == 'dev' %}
{{ stylesheet_link('res/css/signin.css') }}
{% elseif resourceLoad == 'dev-server' %}
{{ stylesheet_link('http://localhost:8080/res/css/signin.css') }}
{% endif %}

{% if resourceLoad == 'dev' %}
{{ javascript_include('res/entrySignin.bundle.js') }}
{% elseif resourceLoad == 'dev-server' %}
{{ javascript_include('http://localhost:8080/res/entrySignin.bundle.js') }}
{% endif %}


27.4k
Accepted
answer
edited May '14

{{ stylesheet_link(path~'res/css/signin.css') }}

And set path in your ControllerBase depending on your resourceLoad value



41.7k

~ is the string concatenation operator for Volt.

Volt other operators