0

In my website i have some pages with jquery lightbox and some pages without lightbox, to load the packages i use following in my controller function which loads the package and assign that to the placeholder.

public function loadJSLightbox2()
{
    $this->assets
        ->collection('lightboxJs')
        //->setPrefix($this->config->site->cloud_url)
        ->addJs('web/dist/lightbox2/dist/js/lightbox.min.js');
    $this->assets
        ->collection('lightboxCss')
        //->setPrefix($this->config->site->cloud_url)
        ->addCss('web/dist/lightbox2/dist/lightbox.min.css');
}

However in my volt main template (master template) i have define the place holders like below,

 {{ assets.outputJs('lightboxJs') }}
 {{ assets.outputCss('lightboxCss') }}

this works fine as long we this loadJSlightbox2 functions is called when loading the page. In pages where i dont need to load the plugin (where these two asset are empty) i get error called as below.

Phalcon\Assets\Exception: The collection does not exist in the manager

How do i archive this optional plugin behavior in with phalcon asset management tools in my web application ?

mahen3d
  • 7,047
  • 13
  • 51
  • 103
  • The syntax is right, looks like the loadJSLightbox2 function is not called properly. Where and when do you call it? – Eugene Sue Mar 16 '16 at 14:37

1 Answers1

0

I fixed the issue using following code,

{% for key, collection in assets.getCollections() %}
    {% if key == 'origin' %}
        {{ assets.outputJs('origin') }}
    {% endif %}
    {% if key == 'lightboxJs' %}
        {{ assets.outputJs('lightboxJs') }}
    {% endif %}
    {% if key =='colorboxJs' %}
        {{ assets.outputJs('colorboxJs') }}
    {% endif %}
{% endfor %}
mahen3d
  • 7,047
  • 13
  • 51
  • 103