-
Notifications
You must be signed in to change notification settings - Fork 33
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
Support for partials #217
Comments
You can do this with template functions: A simple example by only adding a way to include html files: ./app/init.go
To use this, add to your template: Instead of writing an anonymous function in init.go like in this simple example, you can add a component function to better organize your code. |
@AugustHell I know I can add a function to include partials, but this is a feature request because I believe it's an important feature for a web framework. |
@vcraescu Thanks for bringing up use case, which would be beneficial to aah users. @AugustHell Thanks for your inputs and helping aah community. I will take your inputs, generalize and add it aah view template functions in next release. |
@vcraescu @AugustHell I was implementing partials template func then I thought following idea. Have a look and please let me know your thoughts. Existing feature:
Currently supported syntax of
So, add partials capability into func E.g.: adding new syntax instead new tmpl func
|
I very much like this:
|
@jeevatkm I don't think it's a good idea to support both absolute and relative paths because it's confusing. Only relative paths to project root should be allowed.
So only |
@AugustHell Yes, @vcraescu Yeah idea is to have ability to For e.g: <!-- absolute path syntax -->
{{ include "/views/users/form.html" . }}
{{ include "/users/form.html" . }}
<!-- relative path syntax -->
{{ include "users/form.html" . }} Also order of resolving relative path has crux in it. Example- <!-- Load from respect to parent template (currently this principle is not fully exists
because include only loads the template within directory-tree of common).
I would like to bring this capability into aah view engine -->
{{ include "users/form.html" . }}
<!-- Load from respect to view root directory. -->
{{ include "/views/users/form.html" . }}
{{ include "/users/form.html" . }} We can advocate bring the same order of path resolve principle without beginning slash I hope I have explained it in detail about my thoughts. |
@jeevatkm Makes sense what you're saying if BC is your concern. It might be a good idea to have the imports relative to views folder and not to project dir. I have in mind some cases where this might be handy. But
these 2 are a big NO-NO from my point of view. 2 different paths that does same thing. Too much "magic" which is error prone and hard to maintain in long term. So, if you want to keep existing functionality (importing from "common" directory) then I suggest just 2 cases:
Although, I would drop the include from common folder cause because it's so uncommon and I don't see any advantages having such a feature. |
@vcraescu Yes, I agree. Since new feature would satisfy including a files from common directory too. I think, I will deprecated the existing behavior of |
Done 😄 |
It will be good to have support for partial templates. As far as I can, at this moment, you can only include templates from "common" folder which is good but It's not enough in a large web application.
Need to be able to do something like this:
{{ partial("users/form.html") }}
Right now I'm just duplicating code because I don't want to put all the partials inside common folder since those templates only makes sense in user context and I will not use them anywhere else.
Thanks!
The text was updated successfully, but these errors were encountered: