mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02: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:
@@ -194,12 +194,13 @@ func (p *Page) IsPage() bool {
|
||||
// Param is a convenience method to do lookups in Page's and Site's Params map,
|
||||
// in that order.
|
||||
//
|
||||
// This method is also implemented on Node.
|
||||
// This method is also implemented on Node and SiteInfo.
|
||||
func (p *Page) Param(key interface{}) (interface{}, error) {
|
||||
keyStr, err := cast.ToStringE(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
keyStr = strings.ToLower(keyStr)
|
||||
if val, ok := p.Params[keyStr]; ok {
|
||||
return val, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user