hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

safeJS.md (1136B)

    1 ---
    2 title: safeJS
    3 # linktitle:
    4 description: Declares the provided string as a known safe JavaScript string.
    5 date: 2017-02-01
    6 publishdate: 2017-02-01
    7 lastmod: 2017-02-01
    8 categories: [functions]
    9 menu:
   10   docs:
   11     parent: "functions"
   12 keywords: [strings]
   13 signature: ["safeJS INPUT"]
   14 workson: []
   15 hugoversion:
   16 relatedfuncs: []
   17 deprecated: false
   18 draft: false
   19 aliases: []
   20 ---
   21 
   22 In this context, *safe* means the string encapsulates a known safe EcmaScript5 Expression (e.g., `(x + y * z())`).
   23 
   24 Template authors are responsible for ensuring that typed expressions do not break the intended precedence and that there is no statement/expression ambiguity as when passing an expression like `{ foo:bar() }\n['foo']()`, which is both a valid expression and a valid program with a very different meaning.
   25 
   26 Example: Given `hash = "619c16f"` defined in the front matter of your `.md` file:
   27 
   28 * <span class="good">`<script>var form_{{ .Params.hash | safeJS }};…</script>` &rarr; `<script>var form_619c16f;…</script>`</span>
   29 * <span class="bad">`<script>var form_{{ .Params.hash }};…</script>` &rarr; `<script>var form_"619c16f";…</script>`</span>