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.


1 Answer 1


Would it be an option for you to use


Yii2 Aliases


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.