Answers.Body: <p>Pretty sure you have to resolve the alias with twig, you could short it down to just:</p>
  <pre><code>&lt;link refl=&quot;stylesheet&quot; href=&quot;{{ alias('@web') }}/css/app.css&quot;&gt;
  </code></pre>
  <p>But you also dont need the full url for the css file:</p>
  <pre><code>&lt;link refl=&quot;stylesheet&quot; href=&quot;/css/app.css&quot;&gt;
  </code></pre>
  <p>Should work just fine too.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-04T10:44:16.040Z
Answers.Text: Thank you so much for pointing out the correct way to use the alias in Twig. I was stuck trying to use @web directly within an attribute, and I totally missed resolving it with {{ alias('@web') }}/css/app.css or just simplifying with the relative /css/app.css. It seems so clear now!
Answers.UserDisplayName: arche
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-04T10:36:42.097Z
Answers.LastActivityDate: 2023-10-04T10:36:42.097Z
Answers.UserDisplayName: Syversen
Body: <p>Is this a bug or is this me ? (I'm a new to craft)</p>
  <p>When using the @web alias directly within an attribute in a Twig template, the alias doesn't seem to be resolved to its corresponding URL. Instead, the literal string @web is rendered in the final output.</p>
  <p><strong>Steps to Reproduce:</strong></p>
  <ol>
  <li>Define the @web alias in general.php:</li>
  </ol>
  <pre><code>-&gt;aliases([
      '@web' =&gt; 'http://craftsite.ddev.site/'
  ])
  
  </code></pre>
  <p>2.Use the alias directly in a Twig template's attribute:</p>
  <pre><code>&lt;link rel=&quot;stylesheet&quot; href=&quot;@web/css/app.css&quot;&gt;
  
  </code></pre>
  <ol start="3">
  <li>View the rendered HTML. The output is:</li>
  </ol>
  <pre><code>&lt;link rel=&quot;stylesheet&quot; href=&quot;@web/css/app.css&quot;&gt;
  
  </code></pre>
  <p>The expected output should be:</p>
  <pre><code>&lt;link rel=&quot;stylesheet&quot; href=&quot;http://craftbites.ddev.site/css/app.css&quot;&gt;
  </code></pre>
  <p><strong>Workaround:</strong></p>
  <p>Resolving the alias to a variable first and then using that variable in the attribute resolves the issue:</p>
  <pre><code>{% set baseUrl = alias('@web') %}
  &lt;link rel=&quot;stylesheet&quot; href=&quot;{{ baseUrl }}/css/app.css&quot;&gt;
  
  </code></pre>
  <p><strong>Environment:</strong></p>
  <ul>
  <li>Craft version: 4.5</li>
  <li>PHP version: 8.1</li>
  </ul>
  
Tags: <craft4><css><alias>
Title: Alias not being resolved directly within an attribute in Twig templates
ThreadText: # Alias not being resolved directly within an attribute in Twig templates
  
  (Asked by: username_0 on 2023-10-04)
  
  Is this a bug or is this me ? (I'm a new to craft)
  
  When using the @web alias directly within an attribute in a Twig template, the alias doesn't seem to be resolved to its corresponding URL. Instead, the literal string @web is rendered in the final output.
  
  **Steps to Reproduce:**
  
  1. Define the @web alias in general.php:
  
  ```
  ->aliases([
      '@web' => 'http://craftsite.ddev.site/'
  ])
  
  ```
  
  2.Use the alias directly in a Twig template's attribute:
  
  ```
  <link rel="stylesheet" href="@web/css/app.css">
  
  ```
  
  3. View the rendered HTML. The output is:
  
  ```
  <link rel="stylesheet" href="@web/css/app.css">
  
  ```
  
  The expected output should be:
  
  ```
  <link rel="stylesheet" href="http://craftbites.ddev.site/css/app.css">
  
  ```
  
  **Workaround:**
  
  Resolving the alias to a variable first and then using that variable in the attribute resolves the issue:
  
  ```
  {% set baseUrl = alias('@web') %}
  <link rel="stylesheet" href="{{ baseUrl }}/css/app.css">
  
  ```
  
  **Environment:**
  
  * Craft version: 4.5
  * PHP version: 8.1
  
  **Tags:** craft4, css, alias
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-10-04. Score: 1 | Accepted answer
  
  Pretty sure you have to resolve the alias with twig, you could short it down to just:
  
  ```
  <link refl="stylesheet" href="{{ alias('@web') }}/css/app.css">
  
  ```
  
  But you also dont need the full url for the css file:
  
  ```
  <link refl="stylesheet" href="/css/app.css">
  
  ```
  
  Should work just fine too.
  
  > **Comments:**
  > **username_0**: Thank you so much for pointing out the correct way to use the alias in Twig. I was stuck trying to use @web directly within an attribute, and I totally missed resolving it with {{ alias('@web') }}/css/app.css or just simplifying with the relative /css/app.css. It seems so clear now!  
  
  ---
  
  