miguel/assetic-angular-js-bundle

Assetic filter to output AngularJS templates for the template cache

Installs: 3 398

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 5

Type:symfony-bundle

0.1.3 2017-07-06 21:02 UTC

This package is not auto-updated.

Last update: 2024-04-23 15:21:51 UTC


README

Simple Assetic filter to feed the $templateCache.

Installation

composer require miguel/assetic-angular-js-bundle

Requirements

Any Symfony2 2.3+ application will do.

Configuration

Edit your config.yml and add a section miguel_assetic_angular_js:

.. code-block:: yaml miguel_assetic_angular_js: app_name: app

If you don't do it the default app_name will be app.

Usage

Just include the Angular templates as any other javascript resource using the javascripts Twig helper and apply the angular filter to them.

{% javascripts filter="angular"
    '@BundleName/Resources/views/aTemplate.html'
    '@BundleName/Resources/views/moarTemplates/*.html'
    'assets/app/tpl/contact/contact.html'
    %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

The resulting output will be something like this:

angular.module("app").run(["$templateCache", function($templateCache) {
  $templateCache.put("BundleName/views/aTemplate.html", "HTML here");
}]);
angular.module("app").run(["$templateCache", function($templateCache) {
  $templateCache.put("BundleName/views/fooTemplate.html", "HTML here");
}]);
angular.module("app").run(["$templateCache", function($templateCache) {
  $templateCache.put("assets/app/tpl/contact/contact.html", "HTML here");
}]);
// ...

If the asset is in a bundle then the Resources/ part is removed.

Now, to use the template a dependency on the module name must be set and after that the template can be retrieved using the templates URL:

<div data-ng-include="BundleName/views/aTemplate.html"></div>
<div data-ng-include="assets/app/tpl/contact/contact.html"></div>

Of course, wherever a template URL can be specified, the above will work as it is in the default AngularJS template cache.

License

MIT