ripaclub/zf2-hanger-snippet 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ripaclub/zf2-hanger-snippet

Composer 安装命令:

composer require ripaclub/zf2-hanger-snippet

包简介

A module to attach HTML/JS snippets into a ZF2 application

README 文档

README

Travis Packagist License Scrutinizer Scrutinizer Coverage

This ZF2 Module aims to provide a fast way to configure and append code snippeds for JS libraries.

Rationale

Often happens to have to set up a Javascript library and many times it would be nice to have a place where you can configure them and perhaps with the ability to override the configuration rather than throw them in the view.

Installation

Via Composer

Add ripaclub/zf2-hanger-snippet to your composer.json

{
   "require": {
       "ripaclub/zf2-hanger-snippet": "~1.0.6"
   }
}

Setup

In your layout before the body closing tag

<?php echo $this->hangerSnippet(); ?>

Optionally, if you need to add more placements:

<?php echo $this->hangerSnippet()->render('placementName'); ?>

Configuration

return [
    'hanger_snippet' => [
        'enable_all' => true, //if not specified true by default
        'snippets' => [
            'snippet-name' => [
                'config_key'  => '', // Config node in the global config, if any, retrivied data will be merged with values then passed to the template
                'template'    => '', // Template script path, if not specified 'hanger-snippet/snippet-name' will be used
                'placement'   => '', // Placement identifier, if not specified the default placement will be used
                'enabled'     => true, // When not specified 'enable_all' value will be used
                'values' => [
                    // Other values for the template
                ],
            ],
        ],
    ],
];

Do not forget to add HangerSnippet module to you application.config.php file.

'modules' => [
        // ...
        'HangerSnippet',
        'Application',
],

Built-in snippets

Google Analytics

Configuration:

return [
    'ga' => [
        'monitoring_id' => 'UA-XXXXXXXX-X',
        'domain'        => 'yourdomain.com',
        'anonymize_ip'  => false, // refer to https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#anonymizeip for more information
        'options' => [
            'siteSpeedSampleRate' => 1,
            'sampleRate' => 100
            // refer to https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference for more options
        ],
    ],

    'hanger_snippet' => [
        'snippets' => [
            'google-analytics' => [
                'config_key' => 'ga', // the config node in the global config, if any
                'values' => [
                    // other values for the template
                ],
            ],
        ],
    ],
];

Facebook JavaScript SDK

Configuration:

return [
    'facebook' => [
           'appId' => '...',
    ],

    'hanger_snippet' => [
        'snippets' => [
            'facebook-sdk' => [
                'config_key' => 'facebook', // the config node in the global config, if any
                'values' => [
                    'async' => false,
                    'status' => true,
                    'xfbml'  => true,
                    'version' => 'v2.2',
                ],
            ],
        ],
    ],
];

Google no CAPTCHA reCAPTCHA

Configuration:

return [
    'grecaptcha2.0' => [
        'uri' => 'https://www.google.com/recaptcha/api.js'
        // Optional API parameters - see https://developers.google.com/recaptcha/docs/display
        'parameters' => [
            'render' => 'onload',
            // 'hl' => '...',
            // 'onload' => '...',
        ],
    ],
    
    'hanger_snippet' => [
        'snippets' => [
            'google-nocaptcha-recaptcha' => [
                'config_key' => 'grecaptcha2.0', // the config node in the global config, if any
                'values' => [
                    'sitekey' => '',
                    // Optional configurations - see https://developers.google.com/recaptcha/docs/display
                    'theme' => 'light',
                    'type' => 'image',
                    'callback' => '...',
                    'expiredCallback' => '...'
                ],
            ],
        ],
    ],
];

The placement of Google ReCaptcha snippet, unlike the others, needs to be specified (it can not be simply appended to the page).

To place this snippet where you need it ...

<?php echo $this->hangerSnippet()->render('google-nocaptcha-recaptcha'); ?>
NOTE

The string google-nocaptcha-recaptcha is the default name of the placement for this snippet (see module.config.php).

Analytics

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2014-03-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固