<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>

CC BY-SA 4.0
2023-10-04T10:44:16.040Z
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!
arche
CC BY-SA 4.0
2023-10-04T10:36:42.097Z
2023-10-04T10:36:42.097Z
Syversen
<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>

<craft4><css><alias>
Alias not being resolved directly within an attribute in Twig templates
# 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:

Define the @web alias in general.php:

->aliases([
    '@web' => 'http://craftsite.ddev.site/'
])


2.Use the alias directly in a Twig template's attribute:




View the rendered HTML. The output is:




The expected output should be:


Workaround:
Resolving the alias to a variable first and then using that variable in the attribute resolves the issue:
{% set baseUrl = alias('@web') %}



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:


But you also dont need the full url for the css file:


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!  

---

