From d1d7702c067dfc18699ab3176970b7aa1c953efe Mon Sep 17 00:00:00 2001 From: Rick Cogley Date: Wed, 3 Feb 2016 22:45:21 +0900 Subject: [PATCH] Add a benefit and a simple example to return current year Thanks @bep! --- docs/content/extras/shortcodes.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/content/extras/shortcodes.md b/docs/content/extras/shortcodes.md index a09923dd9..583c617a7 100644 --- 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 @@ 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: - {{}} + {{}} 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: + + {{}} + +... 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).