Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-11T10:20:52.747Z
Answers.LastActivityDate: 2018-05-11T10:20:52.747Z
Answers.UserDisplayName: Robin Schambach
Body: <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>
  
Tags: <plugin-development>
Title: How can I use aliases in a module / plugin?
ThreadText: # 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](https://www.yiiframework.com/doc/guide/2.0/en/concept-aliases#resolving-aliases)
  
  
  ---
  
  