Skip to content
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

Improve .Page.Fragments.ToHTML #13107

Closed
jmooring opened this issue Dec 4, 2024 · 2 comments · Fixed by #13108
Closed

Improve .Page.Fragments.ToHTML #13107

jmooring opened this issue Dec 4, 2024 · 2 comments · Fixed by #13108
Assignees
Milestone

Comments

@jmooring
Copy link
Member

jmooring commented Dec 4, 2024

The Fragments.ToHTML method on Page takes three arguments:

func (toc *Fragments) ToHTML(startLevel, stopLevel int, ordered bool) template.HTML {
  ...
}

It would be convenient to pass site and/or page parameters to this method, something like:

{{ .Fragments.ToHTML (.Param "toc.startLevel") (.Param "toc.endLevel") true }}

The above throws an error with JSON and TOML site/page parameters because the values are unmarshaled to float64 (JSON) or int64 (TOML). You can work around this with:

{{ .Fragments.ToHTML (.Param "toc.startLevel" | int) (.Param "toc.endLevel" | int) true }}

But it would easier if the method signature were...

func (toc *Fragments) ToHTML(startLevel, stopLevel any, ordered bool) template.HTML {
  ...
}

... with cast.ToIntE, etc.

@bep bep added this to the v0.140.0 milestone Dec 4, 2024
@jmooring jmooring self-assigned this Dec 4, 2024
@bep
Copy link
Member

bep commented Dec 4, 2024

Yea, we could do this (I wish Go generics could help us with this, but I don't think so). Note that should be possible to do:

{{ .Fragments.ToHTML (.Param "toc.startLevel" | int) (.Param "toc.endLevel" | int) true }}

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants