Add shortcut to Scratch from shortcode
This commit is contained in:
parent
bef25432d1
commit
be01f8430e
|
@ -40,6 +40,5 @@ The usage is best illustrated with some samples:
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note:** The examples above uses the special `$` variable, which refers to the top-level node. This is the behavior you most likely want, and will help remove some confusion when using `Scratch` inside page range loops -- and you start inadvertently calling the wrong `Scratch`. But there may be use cases for `{{ .Scratch.Add "key" "some value" }}`.
|
**Note:** The examples above uses the special `$` variable, which refers to the top-level node. This is the behavior you most likely want, and will help remove some confusion when using `Scratch` inside page range loops -- and you start inadvertently calling the wrong `Scratch`. But there may be use cases for `{{ .Scratch.Add "key" "some value" }}`.
|
||||||
**Note:** To use `Scratch` in a `shortcode`, you will have to use the shortcode's Page's `Scratch`: `{{ .Page.Scratch.Add "a1" 12 }}` or `{{ $.Page.Scratch.Add "a1" 12 }}`.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,10 @@ func (scp *ShortcodeWithPage) RelRef(ref string) (string, error) {
|
||||||
return scp.Page.RelRef(ref)
|
return scp.Page.RelRef(ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (scp *ShortcodeWithPage) Scratch() *Scratch {
|
||||||
|
return scp.Page.Scratch()
|
||||||
|
}
|
||||||
|
|
||||||
func (scp *ShortcodeWithPage) Get(key interface{}) interface{} {
|
func (scp *ShortcodeWithPage) Get(key interface{}) interface{} {
|
||||||
if reflect.ValueOf(scp.Params).Len() == 0 {
|
if reflect.ValueOf(scp.Params).Len() == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue
Block a user