<p>Would it be an option for you to use </p>

<pre><code>Craft::getAlias('@webroot');
</code></pre>

<p><a href="https://www.yiiframework.com/doc/guide/2.0/en/concept-aliases#resolving-aliases" rel="noreferrer">Yii2 Aliases</a></p>

CC BY-SA 4.0
2018-05-11T10:20:52.747Z
2018-05-11T10:20:52.747Z
Robin Schambach
<p>I'm writing a module that needs to grab the path of a file.</p>

<p>I know I can use <code>{{ alias('@webroot') }}</code> in the templates to get the root web folder. Is there a way I can do this in module/plugin land?</p>

<p>I've been looking for PHP constants or similar, and landed on <code>$fullpath = CRAFT_BASE_PATH . '/web/' . $filename;</code> which doesn't feel great.</p>

<p>Cheers!</p>

<plugin-development>
How can I use aliases in a module / plugin?
# How can I use aliases in a module / plugin?

(Asked by: username_0 on 2018-05-11)

I'm writing a module that needs to grab the path of a file.

I know I can use `{{ alias('@webroot') }}` in the templates to get the root web folder. Is there a way I can do this in module/plugin land?

I've been looking for PHP constants or similar, and landed on `$fullpath = CRAFT_BASE_PATH . '/web/' . $filename;` which doesn't feel great.

Cheers!

**Tags:** plugin-development


---

## 1 answers

### Answer by username_1 on 2018-05-11. Score: 7 | Accepted answer

Would it be an option for you to use 
Craft::getAlias('@webroot');

Yii2 Aliases


---

