stevenschobert / instafeed.js

A simple Instagram JavaScript plugin for your website
https://instafeedjs.com
MIT License
3.51k stars 859 forks source link

Cant overwrite template with filter transform or render #743

Open kiwo12345 opened 2 years ago

kiwo12345 commented 2 years ago

I am trying to change the template depending if its a image or video but it doesnt seem to work, it just uses the template provided when calling the function

<script src="https://cdn.jsdelivr.net/gh/stevenschobert/instafeed.js@2.0.0rc1/src/instafeed.min.js"></script>
<div class="instagram-module" id="instafeed"></div>

<script type="text/javascript">
    var feed = new Instafeed({
        get: 'user',
        target: 'instafeed',
        limit: 10,
        template: '<a class="instagram-link" href="{{link}}" target="_blank" rel="noopener"><figure class="instagram-figure"><video controls loop><source src="' + image.model.media_url + '" type="video/mp4"/></video><figcaption class="instagram-caption" >{{caption}}</figcaption></figure></a>',
        resolution: 'low_resolution',
        accessToken: 'token',
        filter: function(image) {

            if (image.type == 'image' ) {
                image.template = '<img src="' + image.image + '" />';
            } else {

                image.template = '<video controls loop><source src="' + image.model.media_url + '" type="video/mp4"/></video>';
            }
            return true;
        }
    });
    feed.run();
</script>
emreond commented 1 year ago

Did you able to solve this? I need to also write an if check inside template.