-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Forced template root dir #81
Comments
I built it this way because it's simple and fairly easy to use. Can you explain more about how your project tree is laid out, and how you would like Askama to work in your context? |
I use actix FW and have multiple apps attached to server. Each app with it's underlying logic lives in separate Directory, where I also would like to add the templates. Nerveless I can't really come up with an Idea how to organise this. One thing that comes to my mind, is that I have a choice to load the templates relative to dir where |
However this is not a blocker for me, #82 is :/ |
@djc Thank you for your work. I really like askama.
There're a lot of reasons why someone might want to put templates in a different directory. Example:
The current work around requires one to have an empty One backwards compatible approach to solve this would be to configure the default behavior by switches in For example:
One may also want to treat paths in |
@djc I'll be happy to implement whatever approach you think is best. The above is only my idea. You might have a better one. |
Here's the design I had in mind: there will be an optional [general]
dirs = ["templates", "foo/templates", "../bar/baz/templates"] These are all paths relative to the crate root, and they are searched in order by Does that sound good? |
Sounds good. |
Since I had a question about this on Gitter: I looked at what it could take to do template paths relative to the file defining the context struct. Unfortunately procedural macros right now don't give me a reliable way to figure out the path to the source code, as far as I can tell. Once they do, I definitely wouldn't mind revisiting that as an option, but the paths would have to be marked in some way (either with a path prefix like |
@mashedcode so are you still interested in working on the design as proposed? |
I'm still interested. |
Nice, I'm happy to provide further guidance/mentoring if needed; let me know. |
Me too. |
I also noticed that it isn't possible to add subdirs to the
with the following error:
|
@denysvitali that should be a separate issue. I just tried to create a test to reproduce your error, but that didn't work. Can you give me more detailed steps to reproduce, ideally in a separate issue? Bonus points if you submit it as a PR to the test suite. 😄 diff --git a/testing/templates/sub/inner.html b/testing/templates/sub/inner.html
new file mode 100644
index 0000000..db8a8a4
--- /dev/null
+++ b/testing/templates/sub/inner.html
@@ -0,0 +1 @@
+{{ foo }}
diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs
index 95c14b1..d9b3fcd 100644
--- a/testing/tests/simple.rs
+++ b/testing/tests/simple.rs
@@ -258,3 +258,14 @@ struct Empty;
fn test_empty() {
assert_eq!(Empty.render().unwrap(), "foo");
}
+
+#[derive(Template)]
+#[template(path = "sub/inner.html")]
+struct Subdir {
+ foo: String,
+}
+
+#[test]
+fn test_subdir() {
+ assert_eq!(Subdir { foo: "bar".into() }.render().unwrap(), "bar");
+} |
@djc Sure thing! I'll try create a minimal reproducible test, make a new issue and a PR to fix the problem / add a test (or both 😄) Edit: Nevermind, apparently the problem was with my template file: I was extending a template file, by using |
I think templates should be inside src because it contains rust code |
We recently merged a change so that paths that start with ./ do the right thing. |
Can you show me a example, which I can start with The idea is that I can use vertical slice architecture. I would like to have the corresponding route-handler, html-template, etc. in the "home" directory. Can I also define wildcards? |
I guess I was wrong? Not sure -- please keep the discussion in #877. |
Why? This forces me a 1 way structure, that works bad with my project tree. Please add an option to change the root dir, or better to add multiple ones.
The text was updated successfully, but these errors were encountered: