Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use super()? #825

Closed
reportingissue opened this issue Jun 19, 2023 · 3 comments · Fixed by #827
Closed

How to use super()? #825

reportingissue opened this issue Jun 19, 2023 · 3 comments · Fixed by #827

Comments

@reportingissue
Copy link
Contributor

I'm trying to get the super() macro to work.

rustc 1.70.0 (90c541806 2023-05-31)

Cargo.toml

[dependencies]
askama = {version = "0.11.1"}

page.html

{% extends "base.html" %}

{% block content %}
child
{{super()}}
{% endblock %}

base.html

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>
<body>
{% block content %}
parent
{% endblock %}
</body>
</html>

main.rs

use askama::Template;

#[derive(Template)]
#[template(path="page.html")]
struct Page {}

fn main() {
	println!("{}", Page{}.render().unwrap());
}

The error:

error[E0609]: no field `super` on type `&Page`
 --> src\main.rs:3:10
  |
3 | #[derive(Template)]
  |          ^^^^^^^^ unknown field
  |
  = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

I've tried with { super() }, {{ super }}and {% super() %} but those don't work either. I haven't managed to find a working example on the internet...

@wrapperup
Copy link
Contributor

Use {% call super() %}

@reportingissue
Copy link
Contributor Author

reportingissue commented Jun 19, 2023

Thank you, closing this issue, but perhaps an example should be put in the docs since it is different enough from the standard jinja2 syntax.

@djc
Copy link
Owner

djc commented Jun 20, 2023

@reportingissue if you are able to submit a PR to the docs where you'd have found it, that would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants