Answers.Body: <p>Try this:</p>
  
  <pre><code>{% do view.registerCssFile(siteUrl ~ 'css/print.css', {'media' : 'print'}) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-27T08:54:39.090Z
Answers.Text: Thanks, that worked! Can explain the syntax?
Answers.UserDisplayName: Davina Leong
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-28T09:00:35.620Z
Answers.Text: It's in the twig docs, for example here: https://twig.symfony.com/doc/2.x/templates.html#setting-variables
Answers.UserDisplayName: Udo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-27T07:38:59.807Z
Answers.LastActivityDate: 2019-03-27T07:38:59.807Z
Answers.UserDisplayName: Udo
Body: <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>
  
Tags: <templating>
Title: How to add attributes to links/scripts?
ThreadText: # 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  
  
  ---
  
  