1
0
Fork 0
mirror of https://github.com/gohugoio/hugo.git synced 2024-12-22 11:02:10 +00:00
hugo/docs/content/en/functions/safe/JS.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes 
2024-01-27 10:48:57 +01:00

1.1 KiB

title description categories keywords action aliases
safe.JS Declares the given string as a safe JavaScript expression.
aliases related returnType signatures
safeJS
functions/safe/CSS
functions/safe/HTML
functions/safe/HTMLAttr
functions/safe/JSStr
functions/safe/URL
template.JS
safe.JS INPUT
/functions/safejs

In this context, safe means the string encapsulates a known safe EcmaScript5 Expression (e.g., (x + y * z())).

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.

Example: Given hash = "619c16f" defined in the front matter of your .md file:

  • <script>var form_{{ .Params.hash | safeJS }};…</script><script>var form_619c16f;…</script>
  • <script>var form_{{ .Params.hash }};…</script><script>var form_"619c16f";…</script>