-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Using cyclic refs in <script> kills hugo #1123
Comments
Not sure what you expected to be rendered from the map Yes, it looks like Golang's template engine tries to convert data inside You can tell it to not touch some value by using the
|
Well I certainly wouldn't expect hugo to die :) But the above code works well enough for my use case so feel free to close this. Thanks |
If the Go template handler panics, then it's a bug that should be fixed -- by the Go team. Panic is a good way to signal these issues -- very visible. It doesn't panic in Go 1.4.2 on Linux, btw. |
@rauhs I created this issue over at Go: I'll reopen this issue to keep track of that one. |
Thanks for doing the work. I'd certainly make an effort myself usually but I'm swamped with work and not too familiar with go. |
On the Go issue @bep says:
Why do the Pages have an exported reference to the Site they belong to? Is that actually necessary? You say it would "make the software useless" but I don't follow why this is true. |
Let me rephrase: This object graph was constructed by @spf13 long before I entered the picture. It may be so (I haven't thought too hard about it) that the software could live well without it -- but removing it would be a major and ground-breaking API change. I actually like bi-directional object graphs -- and I must admit it, I was surprised to learn that |
I like bi-directional object graphs too, but I don't usually use them for display. Generally like to create copies of my data in template-specific data structures when using |
The site is actually a pared down copy of the actual site object used only for display however it does contain references to all of the pages. Hugo needs this as each page needs to be able to access other pages on the site for a variety of features (related pages, menus, etc). We could do this with all copy vs references but it would get exponentially more expensive the larger the site is. I think it's possible that we could create a mostly duplicate but pared down page struct that doesn't include the reference back to the site and embed these within the site, this would solve the circular reference but would create a lot of overhead and complexity. Yes we do this with the site, but we only have 1 site instance vs N page instances. |
Note that this commit makes no promise about great JSON output from the encoder, but the cyclic refs should be broken. Fixes gohugoio#1123
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
For instance using
{{.Site.Sections}}
in a<script>
will kill hugo with a stackoverflow. Presumably, golang wants to convert the variable to JSON due to the context and this fails.What is the best way to pass down Hugo variables to javascript?
The text was updated successfully, but these errors were encountered: