<p>Try this:</p>

<pre><code>{% do view.registerCssFile(siteUrl ~ 'css/print.css', {'media' : 'print'}) %}
</code></pre>

CC BY-SA 4.0
2019-03-27T08:54:39.090Z
Thanks, that worked! Can explain the syntax?
Davina Leong
CC BY-SA 4.0
2019-03-28T09:00:35.620Z
It's in the twig docs, for example here: https://twig.symfony.com/doc/2.x/templates.html#setting-variables
Udo
CC BY-SA 4.0
2019-03-27T07:38:59.807Z
2019-03-27T07:38:59.807Z
Udo
<p>How do I add additional attributes values while registering a CSS/JS file?</p>

<p>I want to add a <code>media</code> attribute to one of the CSS links</p>

<p>Example code:</p>

<pre><code>{% do view.registerCssFile(siteUrl ~ 'css/print.css', [ ['media' =&gt; 'print'] ]) %}
</code></pre>

<p>The above code produces an <code>Unexpected token "operator"</code> error.</p>

<templating>
How to add attributes to links/scripts?
# How to add attributes to links/scripts?

(Asked by: username_0 on 2019-03-27)

How do I add additional attributes values while registering a CSS/JS file?
I want to add a media attribute to one of the CSS links
Example code:
{% do view.registerCssFile(siteUrl ~ 'css/print.css', [ ['media' => 'print'] ]) %}

The above code produces an Unexpected token "operator" error.

**Tags:** templating

---

## 1 answers

### Answer by username_1 on 2019-03-27. Score: 1 | Accepted answer

Try this:
{% do view.registerCssFile(siteUrl ~ 'css/print.css', {'media' : 'print'}) %}

> **Comments:**
> **username_0**: Thanks, that worked! Can explain the syntax?  
> **username_1**: It's in the twig docs, for example here: https://twig.symfony.com/doc/2.x/templates.html#setting-variables  

---

