Templa...Script(3pm)
π Template::Plugin::JavaScript π
okay bestie, so this is a Perl module from the User Contributed Perl Documentation collection, and it's filed under section 3pm β that's the "Perl module" section, iykyk. It lives in the Template::Plugin::JavaScript namespace and it is literally here to make your text safe to drop inside JavaScript. No cap. β¨
πΈ NAME πΈ
Template::Plugin::JavaScript β encodes text so it's safe to use in JavaScript. That's the whole job. It's giving bodyguard energy for your strings. π
π¦ SYNOPSIS π¦
Here's the vibe in action:
[% USE JavaScript %]
<script type="text/javascript">
document.write("[% sometext | js %]");
</script>
So you USE JavaScript, and then you pipe your text through the js filter before it goes anywhere near document.write. Simple as that. Periodt. π
β¨ DESCRIPTION β¨
Template::Plugin::JavaScript is a TT filter β a Template Toolkit filter, for the uninitiated β that filters your text so it can be safely used inside JavaScript quotes. Because raw text inside JS quotes? Absolutely not. It would simply end your whole script. π
So like, watch this:
[% USE JavaScript %]
document.write("[% FILTER js %]
Here's some text going on.
[% END %]");
will become:
document.write("\nHere\'s some text going on.\n");
See what happened there? The newlines turned into \n, and that little apostrophe in "Here's" got itself an escape backslash and became \'. So now the quotes don't get confused, the string stays a string, and nobody's JavaScript breaks. It's honestly iconic behaviour. π
π AUTHOR π
The original idea comes from Movable Type's encode_js global filter. Credit where credit is due, fr fr. π«Ά
Tatsuhiko Miyagawa <miyagawa@bulknews.net>
And the licensing tea: this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Slay. π
π₯ SEE ALSO π₯
Apache::JavaScript::DocumentWriteβ another lil friend in this same general department, go check it out bestie. π
and that's the whole page, babe π
β this was perl v5.36.0, dated 2022-12-10, straight from the Templa...Script(3pm) corner of the manual. go forth and escape your strings responsibly πβ¨
π¦ where this page comes from
- debian bookworm: libtemplate-plugin-javascript-perl 0.02-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtemplate-plugin-javascript-perl 0.02-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtemplate-plugin-javascript-perl 0.02-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtemplate-plugin-javascript-perl 0.02-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtemplate-plugin-javascript-perl 0.02-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms