ref: d1d7702c067dfc18699ab3176970b7aa1c953efe
parent: 49c2761b28130c70d5d228a89dad044711556136
author: Rick Cogley <[email protected]>
date: Wed Feb 3 17:45:21 EST 2016
Add a benefit and a simple example to return current year Thanks @bep!
--- a/docs/content/extras/shortcodes.md
+++ b/docs/content/extras/shortcodes.md
@@ -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 @@
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
@@ -165,7 +169,7 @@
You want to include a single tweet into your blog post? Everything you need is the URL of the tweet, e.g.:
-
+
* https://twitter.com/spf13/status/666616452582129664
Pass the tweet's ID from the URL as parameter to the shortcode as shown below:
@@ -180,7 +184,7 @@
Copy the ID from behind `v=` and pass it the shortcode:
- {{</* youtube w7Ft2ymGmfc */>}}
+ {{</* youtube w7Ft2ymGmfc */>}}
Furthermore, you can autostart the embedded video by setting the `autostart` parameter to true. Remember that you can't mix named an unamed parameters. Assign the yet unamed video id to the parameter `id` like below too.
@@ -372,5 +376,15 @@
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).