mirror of
https://github.com/tiennm99/hugoDocs.git
synced 2026-10-16 10:15:13 +00:00
Namespace functions and methods
This commit is contained in:
1 parent
40212779ae
commit
723a827fdc
687 files changed
+20449
-5821
No files matched your search
@@ -0,0 +1,50 @@
|
||||
---
|
||||
title: Parent
|
||||
description: Returns the parent shortcode context in nested shortcodes.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: hugolib.ShortcodeWithPage
|
||||
signatures: [SHORTCODE.Parent]
|
||||
---
|
||||
|
||||
This is useful for inheritance of common shortcode parameters from the root.
|
||||
|
||||
In this contrived example, the "greeting" shortcode is the parent, and the "now" shortcode is child.
|
||||
|
||||
{{< code file="content/welcome.md" lang=md copy=false >}}
|
||||
{{</* greeting dateFormat="Jan 2, 2006" */>}}
|
||||
Welcome. Today is {{</* now */>}}.
|
||||
{{</* /greeting */>}}
|
||||
{{< /code >}}
|
||||
|
||||
{{< code file="layouts/shortcodes/greeting.html" lang=go-html-template copy=false >}}
|
||||
<div class="greeting">
|
||||
{{ trim .Inner "\r\n" | .Page.RenderString }}
|
||||
</div>
|
||||
{{< /code >}}
|
||||
|
||||
{{< code file="layouts/shortcodes/now.html" lang=go-html-template copy=false >}}
|
||||
{{- $dateFormat := "January 2, 2006 15:04:05" }}
|
||||
|
||||
{{- with .Params }}
|
||||
{{- with .dateFormat }}
|
||||
{{- $dateFormat = . }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
{{- with .Parent.Params }}
|
||||
{{- with .dateFormat }}
|
||||
{{- $dateFormat = . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- now | time.Format $dateFormat -}}
|
||||
{{< /code >}}
|
||||
|
||||
The "now" shortcode formats the current time using:
|
||||
|
||||
1. The `dateFormat` parameter passed to the "now" shortcode, if present
|
||||
2. The `dateFormat` parameter passed to the "greeting" shortcode, if present
|
||||
3. The default layout string defined at the top of the shortcode
|
||||
Reference in new issue
Block a user