gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.63k stars 7.45k forks source link

Passing extra information to a partial template instantiation #444

Closed yacoob closed 9 years ago

yacoob commented 10 years ago

I'd like to know whether there's any best practice about passing extra arguments to a partial template. Let's assume I have a partial template like this:

<button class='btn btn-default btn-sm' type='button'>
<span class='glyphicon glyphicon-chevron-right'></span>
</button>

I'd like to be able to use a single template to produce a button with glyphicon-chevron-right and glyphicon-chevron-left. However, as far as I can tell:

Any other way to get this functionality? Currently I'm simply defining two separate templates, but that's clumsy.

spf13 commented 10 years ago

I understand what you are asking to do. Not sure what the best solution is for it today. Would need to think about a good solution.

ryan-kimber commented 10 years ago

Any update on this?

Is it possible for to declare a map as a variable and pass that?

chibicode commented 9 years ago

Ran into this issue today as well - wasn't sure if my understanding of Go template was bad, or if there's no good way. I would have spent less time getting stuck if documentation mentioned that there's no good way. I was trying to migrate a Jekyll theme, and Jekyll has a way to pass multiple parameters to its "includes" call.

spf13 commented 9 years ago

It seems the best solution so far has been the .Scratch feature that @bep recently added.

chibicode commented 9 years ago

@spf13 wow, thank you for a quick reply! @bep that's great!

For everyone else, here's the relevant pull request: https://github.com/spf13/hugo/pull/746

Hopefully the documentation page reflects the change soon: http://gohugo.io/extras/scratch

bep commented 9 years ago

I don't think we'll gonna provide anything "smarter" than Scratch anything soon, unless provided by the Go templates -- so close this. Hate open issues :-)

bep commented 9 years ago

Oh, and until 0.13 gets out in the open -- the latest docs can be read nicely at https://github.com/spf13/hugo/blob/master/docs/content/extras/scratch.md

beaspider commented 8 years ago

0.15 introduces a map that can be used for this https://github.com/spf13/hugo/pull/1463 See dict function http://gohugo.io/templates/functions/#dict

github-actions[bot] commented 2 years ago

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.