How to specify different template_dir for different sub-apps? #1674
Replies: 16 comments
-
This crate is where I'd like to be able to add some additional templates for a login and a logout page. |
Beta Was this translation helpful? Give feedback.
-
Can you before more specific about what you're calling a "module" here and point me to where in your code these modules are defined as well as where the separate templates live? If you're launching multiple instances of |
Beta Was this translation helpful? Give feedback.
-
Sure thing! I've moved things around a little bit to make it more clear. Everything is on the The "core" application is called bellhop, and lives here. I'm doing some refactoring to support different types of authentication. I've moved some routes from the I'm having trouble figuring out how to move the templates from here into the |
Beta Was this translation helpful? Give feedback.
-
@tecywiz121 I'm sorry, but I'm still not sure if I totally understand. Here's what I've grokked thus far:
Is that the correct lay of the land? If so, then the answer to your question depends on which templates, if any, are shared by If they are sharing templates, then you can simple use the same |
Beta Was this translation helpful? Give feedback.
-
No worries, I'm probably explaining myself poorly. I'm coming from a django background, so I'm probably taking a lot for granted. I really appreciate you taking the time to respond!
I have most of a single Rocket application at The intended design is to be able to compose together
I wouldn't call it a "distinct" Rocket application. It's probably closer to a fairing. In fact, it probably should be a fairing now that I think about it.
Correct.
Yes, but I don't want them there anymore. I'd rather them be in
Other than |
Beta Was this translation helpful? Give feedback.
-
@tecywiz121 I think everything I suggested afterwards still applies. Can you take a look? |
Beta Was this translation helpful? Give feedback.
-
I did read your suggestions, but I don't think they'll work for my use case. I believe you presented three options:
Here are my follow-up questions/comments.
This would be perfect! Since the plugin (
This definitely won't work, since as far as I know, a running executable can't have multiple values for the same environment variable.
Like you mentioned, this is what I'm doing now. The problem with this approach is that it requires all plugin's templates to be added to the This poses a significant problem if the plugins can't be released open source, which is going to be true of some of the plugins I'll be writing. |
Beta Was this translation helpful? Give feedback.
-
This actually touches on a bigger, more complex issue: in what way will plugins normally be "plugged in" to the overall app? And what aspects of this happen at compile time and at runtime? Here are a few points that might help with your design:
This also all depends on who--you, developers, packagers, end users, etc.--will be "choosing" plugins and what resources they will have access to at the time. |
Beta Was this translation helpful? Give feedback.
-
I'll leave the general case up to greater minds than mine, but in Bellhop's case, the plugins are all compiled together in
This is actually a surprisingly simple workaround. I'll go looking around, but do you have any recommendations?
I don't think it's possible to access this from the interface
To do this with Cargo, I think I'd have to write a
This is what I had suggested in the original post: switching |
Beta Was this translation helpful? Give feedback.
-
This sounds like you need to provide plugins as
Template::custom would help with this. To be clear, this approach would still require the plugin's templates to be either hardcoded into the binary (e.g. with Since this is all getting a bit off-topic from Rocket itself, I'll focus from now onward on the only thing I think Rocket is in a position to improve:
I think this wouldn't actually help much in your case, so I'm not (yet) convinced it should be added. A person or build process would still have to specify the multiple |
Beta Was this translation helpful? Give feedback.
-
Thanks for the pointer to
I don't see how having multiple directories is different in that regard compared to having a single directory. Someone still has to set In my documentation for each plugin, I'd add a section like:
|
Beta Was this translation helpful? Give feedback.
-
For comparison I was thinking of this, which doesn't involve modifying
Where "/opt/bellhop/templates/bellhop_auth_dummy" contains the plugin templates. The bottom line: I'm not opposed to supporting multiple |
Beta Was this translation helpful? Give feedback.
-
I'm trying out registering a second template directory with
The odd part is that this line prints
That's good to hear. I'll keep investigating for now. Thanks for the help! |
Beta Was this translation helpful? Give feedback.
-
Aha, that's an unfortunate (and somewhat confusing) consequence of the current design. I'll have to think about this a bit more. It would be nice if templates added manually (e.g. small helpers or |
Beta Was this translation helpful? Give feedback.
-
Is it possible to directly add templates to the context used by |
Beta Was this translation helpful? Give feedback.
-
As of yesterday on |
Beta Was this translation helpful? Give feedback.
-
Hey! I'm using rocket 0.4 to build a pretty simple web application, but I have some plugable modules that have their own views/templates.
I'd like to keep each module's templates with that module, but I can't figure out how to specify different
template_dir
values.This seems like it's related to #394, but is a much simpler problem to solve (if it isn't already!) A possible solution would be to have a
template_dirs
variable that accepts an array of directories to search instead.Beta Was this translation helpful? Give feedback.
All reactions