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

A little issue with template inheritiance. #375

Closed
afidegnum opened this issue Nov 3, 2020 · 6 comments
Closed

A little issue with template inheritiance. #375

afidegnum opened this issue Nov 3, 2020 · 6 comments

Comments

@afidegnum
Copy link

afidegnum commented Nov 3, 2020

I'm trying to implement a template inheritance with askama which is very handy in template. however i have found myself in few errors, where i'm confused on how to implement the template inheritance.

this is the project repo for the structure.. however, i'm getting the following errors.

error[E0726]: implicit elided lifetime not allowed here
   --> src/main.rs:282:6
    |
282 | impl LayoutTemplate {
    |      ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`

error[E0599]: no method named `get_specific` found for struct `std::string::String` in the current scope
   --> src/main.rs:351:15
    |
351 |     let t = s.get_specific(&menu);
    |               ^^^^^^^^^^^^ method not found in `std::string::String`

@djc
Copy link
Owner

djc commented Nov 5, 2020

You forgot to add a Cargo.toml to the repo, which makes it hard to test.

@afidegnum
Copy link
Author

hi, sorry i didn't pay attention, i have added Cargo.toml

@djc
Copy link
Owner

djc commented Nov 5, 2020

So this seems to help a little:

diff --git a/templates/index.html b/templates/index.html
index ed3df67..33945ad 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -1,4 +1,5 @@
-<!DOCTYPE html>
+{% extends "layout.html" %}
+!DOCTYPE html>
 <html>
 <head>
     <meta charset="utf-8" />

Otherwise, your repo is very broken -- numerous files appear to still be missing or in an inconsistent state, and there's a bunch of code that's broken for reasons unrelated to Askama. I suggest you read Askama's documentation section on template inheritance (if you haven't already). I'm happy to answer specific questions or diagnose minimally reproduced issues. If you just want me to write the code for you, you can hire me as on a freelance basis to do that too.

@grv07
Copy link
Contributor

grv07 commented Nov 1, 2021

Hello @djc ,
I think we can mark this one as closed.

I really like the project and want to contribute as much as possible.
I don't know the policy yet, but I am having a hard time selecting my new bug to work because of no labels and unclosed bugs.

I think a little bug cleaning is required :) .

Thanks,

@djc
Copy link
Owner

djc commented Nov 2, 2021

@grv07 thanks! I don't have much to suggest, maybe @vallentin has some ideas? If you're up for a bigger project, a handlebars-compatible frontend would be very interesting.

@djc djc closed this as completed Nov 2, 2021
@vallentin
Copy link
Collaborator

@grv07 If it doesn't specifically have to be a bug, then there's a few things in #427, which might be relatively straight forward to implement, e.g. loop.length. If you're interested and unsure how to get started or get stuck, then feel free to reach out :)

I'm just writing a quick comment, so I might know a few bugs, but don't really recall any right now.


One thing that comes to mind, and I'm not even sure whether it's something we can prevent. Is that if you incorrectly do:

{{ "foo" + "bar" }}

Then the compiler will suggest using .to_owned(), but it shows changing #[derive(Template)] to #[derive(Template.to_owned())]. Not sure if we're able to suppress those hints though.

error[E0369]: cannot add `&str` to `&str`
  --> askama\examples\example.rs:23:10
   |
23 | #[derive(Template)]
   |          ^^^^^^^^ `+` cannot be used to concatenate two `&str` strings
   |
   = note: this error originates in the derive macro `Template` (in Nightly builds, run with
-Z macro-backtrace for more info)
help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
   |
23 | #[derive(Template.to_owned())]
   |          ^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0369`.
error: could not compile `askama` due to previous error

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

No branches or pull requests

4 participants