summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-10-12 05:51:04 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-10-12 06:11:01 +0200
commit078fad49e2508759aa33995eb0a4464ce0a63595 (patch)
tree8f4b869d8b5acfcfff2ad5e15127f7d4cb3aba95 /hugolib
parent3586d77bd57ceb45e23892a552be616dac0cf7b4 (diff)
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
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/node.go12
-rw-r--r--hugolib/page.go15
2 files changed, 27 insertions, 0 deletions
diff --git a/hugolib/node.go b/hugolib/node.go
index f8f8df594..dcbf0d146 100644
--- a/hugolib/node.go
+++ b/hugolib/node.go
@@ -14,6 +14,7 @@
package hugolib
import (
+ "github.com/spf13/cast"
"html/template"
"sync"
"time"
@@ -86,6 +87,17 @@ func (n *Node) IsMenuCurrent(menuID string, inme *MenuEntry) bool {
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 {
return hugoInfo
}
diff --git a/hugolib/page.go b/hugolib/page.go
index e08e764af..2979822c3 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -132,6 +132,21 @@ func (p *Page) IsPage() bool {
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 {
authors := p.Authors()