Add a benefit and a simple example to return current year
authorRick Cogley <rick.cogley@esolia.co.jp>
Wed, 3 Feb 2016 13:45:21 +0000 (22:45 +0900)
committerAnthony Fok <foka@debian.org>
Sun, 7 Feb 2016 05:04:35 +0000 (13:04 +0800)
Thanks @bep!

docs/content/extras/shortcodes.md

index a09923dd992b6992b4c3fc468b6dbb302383593d..583c617a787140ad5110b64ce756d2163b07acd4 100644 (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
@@ -165,7 +169,7 @@ Assuming that standard Hugo pretty URLs are turned on.
 ### Twitter
 
 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 @@ This shortcode embeds a responsive video player for [YouTube](https://www.youtub
 
 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.
 
@@ -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).