Skip to content
Browse files

docs: Document shortcode error handling

  • Loading branch information...
bep committed Nov 7, 2018
1 parent 5d14d04 commit e456e34bdbde058243eb0a5d3c0017748639e08e
Showing with 24 additions and 0 deletions.
  1. +18 −0 docs/content/en/templates/
  2. +6 −0 docs/content/en/variables/
@@ -346,6 +346,24 @@ This will output the following HTML. Note how the first two `img` shortcodes inh
<img src="/images/three.jpg">

## Error Handling in Shortcodes

Use the [errorf](/functions/errorf) template func and [.Position](/variables/shortcodes/) variable to get useful error messages in shortcodes:

{{ with .Get "name" }}
{{ else }}
{{ errorf "missing value for param 'name': %s" .Position }}
{{ end }}

When the above fails, you will see an `ERROR` log similar to the below:

ERROR 2018/11/07 10:05:55 missing value for param name: "/Users/bep/dev/go/gohugoio/hugo/docs/content/en/variables/"

## More Shortcode Examples

More shortcode examples can be found in the [shortcodes directory for][spfscs] and the [shortcodes directory for the Hugo docs][docsshortcodes].
@@ -26,6 +26,12 @@ toc: false
: provides access to the parent shortcode context in nested shortcodes. This can be very useful for inheritance of common shortcode parameters from the root.

: Contains [filename and position]( for the shortcode in a page. Note that this can be relatively expensive to calculate, and is meant for error reporting. See [Error Handling in Shortcodes](/templates/shortcode-templates/#error-handling-in-shortcodes).

: boolean that returns `true` when the shortcode in question uses [named rather than positional parameters][shortcodes]

0 comments on commit e456e34

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.