Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
View helper for aggregating require()s for use with RequireJS-compatible libraries.
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
config
src/View
test CS fixes
.gitignore Updated to PSR-4
.php_cs CS fixes
.travis.yml
Module.php
README.md
composer.json
phpunit.xml

README.md

PhlyRequireJs

https://travis-ci.org/phly/PhlyRequireJs.svg?branch=master

Simple library providing a ZF2 view helper for aggregating RequireJs calls.

Installation

Install the module via git submodules, unzipping the download zipball, or, later, via Composer.

Enable it in a ZF2 module by adding the "PhlyRequireJs" module to your config/application.config.php file.

If not using in ZF2, but standalone with the ZF2 PhpRenderer, you will need to add the requirejs helper as an invokable to the ViewHelperManager.

Usage

<?php

// require(["foo/bar"], function () {});
$this->requirejs()->append('foo/bar'); 

// require(["foo/bar"], function (bar) { bar.baz(); });
$this->requirejs()->append('foo/bar', 'function (bar) { bar.baz(); }'); 

// Capture the callback
$this->requirejs()->appendAndCaptureCallback('foo/bar'); ?>
function(bar) {
    bar.baz();
    bar.onClick(bar.doSomething);
}
<?php
$this->requirejs()->stopCapture();

// Echo all requires
echo $this->requirejs();

The view helper also defines prepend and prependAndCaptureCallback methods; they work identically, but prepend the require to the start of the list.

LICENSE

BSD-2-Clause

Something went wrong with that request. Please try again.