diff options
author | cetra3 <cetra3@hotmail.com> | 2020-06-29 09:40:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-29 11:40:01 +0200 |
commit | 3248ad939a4b331472dc0fe985546da5a6641204 (patch) | |
tree | 8e1c3f517f68ffa2c43fe85d9a1c43e6d1e33216 /book/src/getting_started.md | |
parent | 6d5d404bb81ef7f75c11c9665df3613e2801b496 (diff) | |
download | askama-3248ad939a4b331472dc0fe985546da5a6641204.tar.gz askama-3248ad939a4b331472dc0fe985546da5a6641204.tar.bz2 askama-3248ad939a4b331472dc0fe985546da5a6641204.zip |
Initial Askama Book (#332)
Diffstat (limited to 'book/src/getting_started.md')
-rw-r--r-- | book/src/getting_started.md | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/book/src/getting_started.md b/book/src/getting_started.md new file mode 100644 index 0000000..4b7fb5f --- /dev/null +++ b/book/src/getting_started.md @@ -0,0 +1,37 @@ +# Getting Started + +First, add the following to your crate's `Cargo.toml`: + +```toml +# in section [dependencies] +askama = "0.8" + +``` + +Now create a directory called `templates` in your crate root. +In it, create a file called `hello.html`, containing the following: + +``` +Hello, {{ name }}! +``` + +In any Rust file inside your crate, add the following: + +```rust +use askama::Template; // bring trait in scope + +#[derive(Template)] // this will generate the code... +#[template(path = "hello.html")] // using the template in this path, relative + // to the `templates` dir in the crate root +struct HelloTemplate<'a> { // the name of the struct can be anything + name: &'a str, // the field name should match the variable name + // in your template +} + +fn main() { + let hello = HelloTemplate { name: "world" }; // instantiate your struct + println!("{}", hello.render().unwrap()); // then render it. +} +``` + +You should now be able to compile and run this code. |