PHPackages                             craftsnippets/javascript-helpers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. craftsnippets/javascript-helpers

ActiveCraft-plugin[Templating &amp; Views](/categories/templating)

craftsnippets/javascript-helpers
================================

Twig tools for working with Javascript in templates

3.0.0(1y ago)11.3kMITPHP

Since Oct 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/craft-snippets/craft-javascript-helpers)[ Packagist](https://packagist.org/packages/craftsnippets/javascript-helpers)[ RSS](/packages/craftsnippets-javascript-helpers/feed)WikiDiscussions craft5 Synced 1w ago

READMEChangelog (5)Dependencies (1)Versions (7)Used By (0)

Javascript helpers plugin for Craft CMS 5.x
===========================================

[](#javascript-helpers-plugin-for-craft-cms-5x)

This plugin allows you to output all static translation messages into Javascript object and to easily transfer any Twig variables into Javascript.

Requirements
------------

[](#requirements)

This plugin requires Craft CMS 5.0.0 or later.

Installation
------------

[](#installation)

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

    ```
     cd /path/to/project

    ```
2. Then tell Composer to load the plugin:

    ```
     composer require craftsnippets/javascript-helpers

    ```
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Javascript helpers.

Javascript helpers Overview
---------------------------

[](#javascript-helpers-overview)

Javascript helpers plugin provides two Twig variables and one filter.

### Twig variables

[](#twig-variables)

- `craft.jsHelpers.getMessages('locale_code')` - returns all static message translations as Twig array. By default it returns them for current site locale, but you can pass specific locale code as optional paramater to overwrite it.
- `craft.jsHelpers.outputMessages('array_name', 'locale_code')` - outputs static message translations into Template as Javascript array, at the end of `` tag. First parameter specifies Javascript array name. By default static message translations are returned for current site locale, but you can pass specific locale code as optional second paramater to overwrite it.

### Twig filters

[](#twig-filters)

- `jsVar('variable_name')` - outputs Twig variable as Javascript variable, at the end of `` tag. For example:

```
{{someTwigVariable|jsVar('some_js_variable')}}

```

Will output Javascript variable named `some_js_variable` into template, containing contents of `someTwigVariable`. Works both for variables with single value and for arrays or objests.

Hint: you can also achieve the same effect without this plugin, by using

```
{% do view.registerJsVar('some_js_variable', someTwigVariable, POS_END) %}

```

Disclaimer
----------

[](#disclaimer)

Brought to you by [Piotr Pogorzelski](http://craftsnippets.com)

Plugin icon by [Benjamin J sperry](https://iconscout.com/free-icon/javascript-15).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~435 days

Total

5

Last Release

673d ago

Major Versions

1.1.1 → 2.0.02022-06-18

2.0.0 → 3.0.02024-07-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/c29f59397bc9cfcc85bb0d6350d68c0d29957c5b3bd1c9f0b7c804a1c3c5df4f?d=identicon)[piotrpog](/maintainers/piotrpog)

---

Top Contributors

[![piotrpog](https://avatars.githubusercontent.com/u/42622545?v=4)](https://github.com/piotrpog "piotrpog (7 commits)")

---

Tags

cmsCraftcraftcmscraft-pluginjavascript helpers

### Embed Badge

![Health badge](/badges/craftsnippets-javascript-helpers/health.svg)

```
[![Health](https://phpackages.com/badges/craftsnippets-javascript-helpers/health.svg)](https://phpackages.com/packages/craftsnippets-javascript-helpers)
```

###  Alternatives

[lewisjenkins/craft-dynamic-fields

Populate Craft fields with dynamic data using the power of Twig.

14667.0k](/packages/lewisjenkins-craft-dynamic-fields)[nystudio107/craft-minify

A simple plugin that allows you to minify blocks of HTML, CSS, and JS inline in Craft CMS templates.

37461.2k29](/packages/nystudio107-craft-minify)[jalendport/craft-preparse

A fieldtype that parses Twig when an element is saved and saves the result as plain text.

1086.4k](/packages/jalendport-craft-preparse)[craftpulse/craft-colour-swatches

Let clients choose from a predefined set of colours and utilise associated colour codes and class names in your templates.

3530.8k2](/packages/craftpulse-craft-colour-swatches)[verbb/footnotes

Adds a footnotes feature to CKEditor fields and Twig templates.

213.3k](/packages/verbb-footnotes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
