-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
text/template: make blocks easier to use #14285
Comments
If you want to a question about the new syntax, please see https://golang.org/wiki/Questions . Thanks. |
@ianlancetaylor -- no, this was plain and simple issue report. If something was unclear, don't hesitate to ask. I'm not sure if this is a bug in the template package or simply some missing documentation, though. |
I think the issue is that hugo does things one way, while the block feature wants to do them another. The deal with blocks is that you create new Maybe @spf13 can comment on the approach taken by Hugo. I am working on a better example of template blocks. |
Hugo's approach is basically:
If I read you correct, this approach will not work with blocks and master/overlay templates, but you would have to get rid of the global and track the individual templates (with funcs and all the other dependencies (templates) duplicated/cloned) in your own registry? I guess that would work, but it sounds like fighting the original design . Not sure what I expected by the new
|
@bep knows this as well as anyone. I'm not sure if I understand this all correctly at all. From my reading of this thread and some of the related ones it sounds to me like go template blocks will use a vanilla *template.Template for the children (overriders)? If so I think the approach the go team has taken makes sense from an implementation perspective, but is also a bit shortsighted. I don't think it's reasonable to assume that people would want a plain I've always thought the templates worked a bit strangely as you need to create a template and then chain off of it to create others, but it's worked really well for Hugo by creating an empty template at the root, customizing it and then all of the others effectively extend it. It's disappointing that this feature would not respect that valid use pattern. Please correct me if I'm wrong. |
CL https://golang.org/cl/19443 mentions this issue. |
The CL that @gopherbot just mentioned is my attempt to demonstrate the intended use of |
@spf13 this sentence
leads me to believe you misunderstand how blocks should be used. You first declare a master |
@adg: I guess the CL was a "yes" to the question above. I suggest you keep this issue open to track obvious improvements to the "master/overlay" feature. I will put the Hugo-issue in freeze-mode for now. |
@bep yes. |
I'm not sure that there's anything to do wrt this issue. Anyone object to my closing it? |
I object. Your new example is just a little slightly more practical example of the same. The If you look at With the current master/overlay-dance you will have to re-implement similar logic yourself, which may or may not be a simple thing, depending on the use case. So, a Simplicity is hard. |
Right. We considered This issue is [now] tracking API improvements that make blocks more useful. Apologies if I misinterpreted the original intent of the issue. |
I just sent a CL with a proposed API addition, similar to what was
discussed when blocks were originally introduced. I'd like to hear people's
thoughts. Is this enough? Does it address the issues?
|
That would be CL https://golang.org/cl/19788 |
Yeah, I was hoping @gopherbot would chime in sooner! |
CL https://golang.org/cl/19788 mentions this issue. |
@agl what you have added is convenience methods that behaves very differently from their I'm sorry if I couldn't convey my message better, but these two methods I think are better left out of the API as is, it will confuse more than it helps. What I would expect of
This is how the template API looks like. There may be technical challenges making this overlay construct fit into that API, but if it's impossible, then just leave it as is. |
It would parse the
In the above, Maybe my construct would make more sense looking like this:
Anyhow, I would expect the (sorry about the username confusion, but agl is about as close to your real name as adg ..) |
I maybe missing something significant but why not keep overlay information in templates themselves?.
Something like this http://play.golang.org/p/qRmZPnKYCF |
@fazal you'll need to describe your proposal in a lot more detail. There On 24 February 2016 at 21:39, fazal notifications@github.com wrote:
|
As Andrew said, I don't see a clear proposal here. Closing this issue. |
Fixes golang/go#14285 Change-Id: I3b32b7fc19960a77778e84cba2a0a95b49dbdf16 Reviewed-on: https://go-review.googlesource.com/19443 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Chris Broadfoot <cbro@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Fixes golang/go#14285 Change-Id: I3b32b7fc19960a77778e84cba2a0a95b49dbdf16 Reviewed-on: https://go-review.googlesource.com/19443 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Chris Broadfoot <cbro@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Fixes golang/go#14285 Change-Id: I3b32b7fc19960a77778e84cba2a0a95b49dbdf16 Reviewed-on: https://go-review.googlesource.com/19443 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Chris Broadfoot <cbro@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Fixes golang/go#14285 Change-Id: I3b32b7fc19960a77778e84cba2a0a95b49dbdf16 Reviewed-on: https://go-review.googlesource.com/19443 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Chris Broadfoot <cbro@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Fixes golang/go#14285 Change-Id: I3b32b7fc19960a77778e84cba2a0a95b49dbdf16 Reviewed-on: https://go-review.googlesource.com/19443 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Chris Broadfoot <cbro@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
I spent a little too much time trying to get the new
block
syntax in Go 1.6 implemented inHugo
, with no success.Which is telling me that you should try to supply a "more real" example in the documentation.
Hugo uses the built-in associative transitive map to store its templates, so adding a new template is something like:
As I understand the new
block
implementation, one needs to first parse it with the master file (with theblock
keywords), then do a "overlay" (a modification, a re-parsing) of the same template with the template with the definitions.How to do that with the above I cannot figure out (other than the simple standalone clone example in the doc -- I could clone it, but how do I replace the template in the map?).
My naive approach would be:
And this works ... for the first template. Adding a second breaks in confusing ways.
Ref. gohugoio/hugo#1832
Also see #3812
The text was updated successfully, but these errors were encountered: