Add a benefit and a simple example to return current year

Thanks @bep!
This commit is contained in:
Rick Cogley 2016-02-03 22:45:21 +09:00 committed by Anthony Fok
parent 49c2761b28
commit d1d7702c06

View file

@ -1,7 +1,7 @@
---
aliases:
- /doc/shortcodes/
lastmod: 2015-11-29
lastmod: 2016-02-03
date: 2013-07-01
menu:
main:
@ -29,6 +29,10 @@ using a predefined template. Note that shortcodes will not work in template
files---if you need a functionality like that in a template, you most likely
want a [partial template](/templates/partials/) instead.
Another benefit is, you can update your shortcode with any related new classes or
techniques, and upon generation, Hugo will easily merge in your changes. You
avoid a possibly complicated search and replace operation.
## Using a shortcode
In your content files, a shortcode can be called by using the `{{%/* name parameters
@ -373,4 +377,14 @@ And will be rendered as:
Please notice that this template makes use of a Hugo-specific template function
called `highlight` which uses Pygments to add the highlighting code.
## Simple Single-word Example: Year
Let's assume you would like to have a shortcode to be replaced by the current year in your Markdown content files, for a license or copyright statement. Calling a shortcode like this:
{{</* year */>}}
... would load your one-line template ``/layouts/shortcodes/year.html``, which contains:
{{ .Page.Now.Year }}
More shortcode examples can be found at [spf13.com](https://github.com/spf13/spf13.com/tree/master/layouts/shortcodes).