diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-01-27 10:48:33 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-01-27 10:48:57 +0100 |
commit | 5fd1e7490305570872d3899f5edda950903c5213 (patch) | |
tree | f0cdc490a0942d720494c0044a64c6397d1ab6a5 /docs/content/en/functions/safe/JS.md | |
parent | fc7de7136acbcf0aef54ae8460c7702bc83709be (diff) | |
parent | 9b0050e9aabe4be65c78ccf292a348f309d50ccd (diff) | |
download | hugo-5fd1e7490305570872d3899f5edda950903c5213.tar.gz hugo-5fd1e7490305570872d3899f5edda950903c5213.zip |
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```
Closes #11925
Diffstat (limited to 'docs/content/en/functions/safe/JS.md')
-rw-r--r-- | docs/content/en/functions/safe/JS.md | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/docs/content/en/functions/safe/JS.md b/docs/content/en/functions/safe/JS.md new file mode 100644 index 000000000..65279b89b --- /dev/null +++ b/docs/content/en/functions/safe/JS.md @@ -0,0 +1,26 @@ +--- +title: safe.JS +description: Declares the given string as a safe JavaScript expression. +categories: [] +keywords: [] +action: + aliases: [safeJS] + related: + - functions/safe/CSS + - functions/safe/HTML + - functions/safe/HTMLAttr + - functions/safe/JSStr + - functions/safe/URL + returnType: template.JS + signatures: [safe.JS INPUT] +aliases: [/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>` |