question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamically loaded with blaze

See original GitHub issue

Hello, Im using MeteorJS and I load my slides with a {{#each }} template helper

        <div class="swiper-container">
            <div class="swiper-wrapper">

                {{#each epis}}
                               <div class="swiper-slide">       
                    <div class="epi">   
                                             ..content here...  
                    </div> 
                                 </div>
                {{/each}}
            </div>
            <div class="swiper-pagination"></div>
        </div>

Im initializing swiper instance on onRendered callback

Template.episLista.rendered = function(){
    var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        slidesPerView: 3,
        slidesPerColumn: 2,
        paginationClickable: true,
        spaceBetween: 10,
    });
}

The swiper isn’t loaded at all… I think that the problem is that the HTML Layout of Swiper can’t be dynamically generated… what do you think ?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
rafaelcorreiapolicommented, Sep 28, 2015

Hi! I had to time to think and made it work with a different approach, using Observe Changes, here’s my code

Template.slider.onRendered(function(){
    slides = [];
    var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        slidesPerView: 3,
        slidesPerColumn: 2,
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
        spaceBetween: 0,            
    })      

    Epis.observer =  Epis.find().observeChanges({
        added: function(id){            
            var epi = Epis.findOne({_id:id});
            swiper.appendSlide('<div class="swiper-slide" id="'+id+'"></div>');
            Blaze.renderWithData(Template.epiItem, {epiId:id}, document.getElementById(id))

            var obj = {
                id: id,
                slide: swiper.slides.length-1
            }
            console.log("adicionando no slide: " + parseInt(swiper.slides.length-1));
            slides.push(obj);
        },
        removed: function(id){
            console.log(_);
            var idx = -1;
            var currentSlide = _.find(slides,function(s){
                idx = idx + 1;
                return s.id==id;
            });
            swiper.removeSlide(currentSlide.slide);
            for (i=idx;i<slides.length;i++){
                slides[i].slide = slides[i].slide - 1
            }
            slides.splice(idx,1);

        },changed:function(id){

            //var epi = Epis.findOne({_id:id});
            //$("#"+id).html('');
            //Blaze.renderWithData(Template.epiItem, {epi:epi}, document.getElementById(id))
        }
    });
});
1reaction
nolimits4webcommented, Sep 24, 2015

You can generate Swiper content dynamically, you just need to init it when it is available in DOM

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically loaded with blaze · Issue #1445 - GitHub
Hello, Im using MeteorJS and I load my slides with a {{#each } ... Dynamically loaded with blaze #1445 ... The swiper isn't...
Read more >
Dynamically loading templates (partials) using Blaze Meteor.js
It allows you to load a template only by its name. Easy thing here because you can let your template handle dynamic names...
Read more >
Using Dynamic Commands - Text Blaze
Text Blaze commands allow you to create dynamic snippets. Commands are replaced when the snippet is inserted with a dynamic value or action....
Read more >
Blaze dynamic template loading vs React dynamic component ...
I'm trying to dynamically load React components based on a string reference in the database. I've done it with Blaze and its straight ......
Read more >
Dynamic Template Includes With Blaze - Discover Meteor
Static VS Dynamic. I'm talking about dynamic template includes. A static template include is the kind we use all the time, like: {{> ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found