定制 craftsnippets/javascript-helpers 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

craftsnippets/javascript-helpers

Composer 安装命令:

composer require craftsnippets/javascript-helpers

包简介

Twig tools for working with Javascript in templates

README 文档

README

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

Requirements

This plugin requires Craft CMS 5.0.0 or later.

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 plugin provides two Twig variables and one filter.

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 <body> 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

  • jsVar('variable_name') - outputs Twig variable as Javascript variable, at the end of <body> 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

Brought to you by Piotr Pogorzelski

Plugin icon by Benjamin J sperry.

统计信息

  • 总下载量: 1.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固