Skip to content

Commit 209b33a

Browse files
Update README.md
1 parent 1b36d43 commit 209b33a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,28 @@ return [
1616
];
1717
```
1818

19-
## Vite
19+
## Vite & Resources
2020
Adds a `@resource` alias for use in templates. This will resolve to either `@webroot/../resources` if the dev server is running, or `@webroot/dist` if not. The We store our static asset files outside of the webroot.
2121

2222
We also provide a `resource()` Twig function that does a similar thing, but resolves to your Vite plugin settings. `devServerPublic` if the dev server is running, or `serverPublic` if not. In practice this resolves to `http://localhost:3000/` and `/dist` respectively.
2323

24+
### Resources in Twig
25+
Through these, you'll be able to refer to resources like JS, CSS, images and fonts - anything in your `/resources` folder in your templates. For example, a common scenario is wanting to include images in your Twig templates. You can use the following options to acheieve this.
26+
27+
```twig
28+
{# Use the `@resources` alias #}
29+
<img src="{{ getAlias('@resource/img/logo.png') }}">
30+
31+
{# Or use the `resource()` Twig function #}
32+
<img src="{{ resource('/img/logo.png') }}">
33+
```
34+
35+
If you need to inline an SVG, it's encouraged to use the [`svg()`](https://craftcms.com/docs/3.x/dev/functions.html#svg) Twig function. With this, your only option is to use an alias.
36+
37+
```twig
38+
{{ svg('@resource/img/logo.svg') }}
39+
```
40+
2441
## Base module
2542
Yii's modules are pretty slim, and we loose a bunch of boilerplating that Craft plugins get for free. We add this in `base/Module`. Every Yii module for a project you create should extend this **not** Yii's module class.
2643

0 commit comments

Comments
 (0)