mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Add Param(key) to Node and Page
This is a convenience method to do lookups in Page's (Page only) and Site's Params map (Page and Node), in that order. Fixes #1462
This commit is contained in:
parent
3586d77bd5
commit
078fad49e2
2 changed files with 27 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
||||||
package hugolib
|
package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/spf13/cast"
|
||||||
"html/template"
|
"html/template"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -86,6 +87,17 @@ func (n *Node) IsMenuCurrent(menuID string, inme *MenuEntry) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Param is a convenience method to do lookups in Site's Params map.
|
||||||
|
//
|
||||||
|
// This method is also implemented on Page.
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func (n *Node) Hugo() *HugoInfo {
|
func (n *Node) Hugo() *HugoInfo {
|
||||||
return hugoInfo
|
return hugoInfo
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,21 @@ func (p *Page) IsPage() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
func (p *Page) Param(key interface{}) (interface{}, error) {
|
||||||
|
keyStr, err := cast.ToStringE(key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if val, ok := p.Params[keyStr]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return p.Site.Params[keyStr], nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Page) Author() Author {
|
func (p *Page) Author() Author {
|
||||||
authors := p.Authors()
|
authors := p.Authors()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue