Skip to content

Commit f23fcfa

Browse files
committed
docs: added clear example of .capsule_ref()
1 parent c3f2a02 commit f23fcfa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

docs/next/en-US/capsules/using.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Using capsules
22

3-
Using capsules in your own code involves a few steps. First, you'll want to create a `capsules/` directory in the root of your project (this is just convention), which is just like `templates/`, but (surprise surprise) for capsules. You'll also probably want to bring [`lazy_static`](https://docs.rs/lazy_static/latest/lazy_static) into your project as a dependency so you can use the *referential defin pattern* of capsule definition. This means, rather than having something like a `get_capsule()` function that you use to get your capsule, you create a static reference to it that you can use from anywhere in your program. This is because, unlike templates, capsules get used in more than one place than just `PerseusApp`: you'll also need them where you want to interpolate them into templates.
3+
Using capsules in your own code involves a few steps. First, you'll want to create a `capsules/` directory in the root of your project (this is just convention), which is just like `templates/`, but (surprise surprise) for capsules. You'll also probably want to bring [`lazy_static`](https://docs.rs/lazy_static/latest/lazy_static) into your project as a dependency so you can use the *referential defin pattern* of capsule definition. This means, rather than having something like a `get_capsule()` function that you use to get your capsule, you create a static reference to it that you can use from anywhere in your program. This is because, unlike templates, capsules get used in more than one place than just `PerseusApp`: you'll also need them where you want to interpolate them into templates. Note that doing this means you should add your capsules to your `PerseusApp` like so:
4+
5+
```rust
6+
.capsule_ref(&*crate::capsules::my::capsule::CAPSULE)
7+
```
48

59
## `Capsule` vs. `Template`
610

0 commit comments

Comments
 (0)