1
0
mirror of https://github.com/gohugoio/hugo.git synced 2024-05-11 05:54:58 +00:00

Consolidate the Param methods

Maps in Viper, Hugo's config backing store, is now properly lower-cased not just on top level, the current situation.

While this is mostly a good thing, as you don't need to know the original casing to look up a value, it will be breaking for people doing direct lookups in the ´Site.Params` map.

We will try to find a solution to this "breakage", but the recommended method to get params values is via the `.Param` methods.

This method is now implemented on `Node`, `Page` and `Site` and is case-insensitive:

* Use `.Param "someKey" ` if you want page param with fall back to site param if not found on page.
* Use `.Site.Param "someKey"` to get a site param

See #2590
This commit is contained in:
Bjørn Erik Pedersen
2016-10-17 19:30:21 +02:00
parent faa64abdc2
commit 58f31d2769
3 changed files with 17 additions and 9 deletions

View File

@@ -24,8 +24,6 @@ import (
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/hugo/helpers"
"github.com/spf13/cast"
)
type Node struct {
@@ -124,13 +122,9 @@ func (n *Node) IsMenuCurrent(menuID string, inme *MenuEntry) bool {
// Param is a convenience method to do lookups in Site's Params map.
//
// This method is also implemented on Page.
// This method is also implemented on Page and SiteInfo.
func (n *Node) Param(key interface{}) (interface{}, error) {
keyStr, err := cast.ToStringE(key)
if err != nil {
return nil, err
}
return n.Site.Params[keyStr], err
return n.Site.Param(key)
}
func (n *Node) Hugo() *HugoInfo {