variar / grav-plugin-unitegallery

Grav plugin to create image galleries with unitegallery js library
MIT License
19 stars 5 forks source link

Is it possible to use this plugin in a non-modular template? #9

Closed ganar closed 6 years ago

ganar commented 7 years ago

I want to add this plugin on blog item page, and created a special template just for the pages with galleries. The plugin seems to load, but it generates this JS error:

Uncaught TypeError: jQuery(...).unitegallery is not a function
    at HTMLDocument.<anonymous> (design:153)
    at i (jquery-2.x.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-2.x.min.js:2)
    at Function.ready (jquery-2.x.min.js:2)
    at HTMLDocument.J (jquery-2.x.min.js:2)

Neither the CSS nor the JS seems to load in the header. Any help is appreciated

variar commented 7 years ago

Hi, could you post the template that you are using?

ganar commented 7 years ago

Yes it is twentyfifteen

ganar commented 7 years ago

I did a change on the item.html.twig substituting the top image for the gallery, in the same way that you document here.

That produced an empty space with the divs for the gallery and the JS that initializes it, but no CSS or JS at the top. .

In the end I followed the instructions you gave for a modular page and it did work.

variar commented 7 years ago

This might be somehow connected with #8. I'll try to setup test site with twentyfifteen and see if modular/non-modular page processing differs.

variar commented 7 years ago

Added crude fix in v1.1.3 version and some documentation (c73ec291ee323c8f557434967e463f26fe3899d2). Please check it out.

ganar commented 7 years ago
  1. I installed the update
  2. Made a new page with the following header"
    title: Laminova
    unitegallery:
    gallery_theme: tiles
    present: true
  3. Created a new template override for twentyfifteen for blog_item.html.twig and included this piece of code
    {% if page.header.unitegallery.present is sameas(true) %}
    <div class="gallery-container post-thumbnail {{ page.header.class }}">
        {{ unite_gallery(page.media.images, '{"gallery_theme":"' ~ page.header.unitegallery.gallery_theme ~ '"}') }}
    </div>
    {% else %}
    <div class="post-thumbnail">
        {{ page.media.images|first.cropZoom(1038,437).html(page.title, page.title, 'attachment-post-thumbnail wp-post-image') }}
    </div>
    {% endif %}

The resulting page rendered this code:

<div class="gallery-container post-thumbnail ">
        <div id="unite-gallery" style="display:none;">
<img alt="" data-description="" src="/images/4/0/f/b/c/40fbcf65962c986bd11523e44b67e5080ac4e659.jpg" data-image="/user/pages/03.case-studies/laminova/001-laminova.jpg">
<img alt="" data-description="" src="/images/f/9/1/c/9/f91c917553add66dc51d1d92119a1d8f3b97059b.jpg" data-image="/user/pages/03.case-studies/laminova/002-lam-mm-v1.png">
<img alt="" data-description="" src="/images/6/9/8/e/3/698e304a62fe77f705c674e2d4f120dd6670148c.jpg" data-image="/user/pages/03.case-studies/laminova/003-lam-mm-v2.png">
<img alt="" data-description="" src="/images/c/b/2/7/a/cb27abf415ac338429973336fbeb042b64a77fc0.jpg" data-image="/user/pages/03.case-studies/laminova/004-lam-prop-v2.0.png">
<img alt="" data-description="" src="/images/9/d/6/3/1/9d631799244281f64af3a0fba526dad99da0ac99.jpg" data-image="/user/pages/03.case-studies/laminova/005-lam-prop-v2.1.png">
<img alt="" data-description="" src="/images/a/e/1/a/8/ae1a8a15e38710f7492e45a463e0cd47ca64306b.jpg" data-image="/user/pages/03.case-studies/laminova/006-lam-prop-v2.3.png">
<img alt="" data-description="" src="/images/b/8/3/6/0/b83600868e1da089dcf87abdb097f9e27f8dc075.jpg" data-image="/user/pages/03.case-studies/laminova/007-form-mm-v1.png">
<img alt="" data-description="" src="/images/9/5/a/7/c/95a7cb998c185ceafac69ad6a322a1d9ec240c64.jpg" data-image="/user/pages/03.case-studies/laminova/008-form-mm-v2.0.png">
<img alt="" data-description="" src="/images/f/9/7/f/b/f97fb0d92b0f00eaaf3d0b8456ecc33a29b83c5f.jpg" data-image="/user/pages/03.case-studies/laminova/009-form-mm-v2.1.png">
</div>
<script type="text/javascript">
              jQuery(document).ready(function(){
                jQuery("#unite-gallery").unitegallery({"gallery_theme":"tiles"});
              });
        </script>

</div>

Still missing JS and CSS in the top or bottom of the page. Am I missing something in the instructions?

variar commented 7 years ago

Try adding assets_in_meta: true to unitegallery configuration in page header. It should be true by default, but in my local testing I've always set in explicitly in page header.

ganar commented 7 years ago

¡Yes! It must be a bug: that did it for us. Galleries are working

variar commented 6 years ago

Tested on fresh install and it worked as expected without assets_in_meta: true in page header. Added extra note to readme. Closing for now.