Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feed works great until I add a template #369

Closed
PhilRedm opened this issue Jan 20, 2016 · 7 comments
Closed

Feed works great until I add a template #369

PhilRedm opened this issue Jan 20, 2016 · 7 comments

Comments

@PhilRedm
Copy link

This works:

<script type="text/javascript">
    var feed = new Instafeed({
        get: 'user',
        userId: '180XXXXXX2',
        target: 'instafeed',
                clientId: '9930blahblahbalhetc9ff',
        limit: 10
    });
    feed.run();
</script>

but this is not:

<script type="text/javascript">
    var feed = new Instafeed({
        get: 'user',
        userId: '180XXXXXX2',
        target: 'instafeed',
                clientId: '9930blahblahbalhetc9ff',
        limit: 10,
        template: '<a href="{{link}}"><img src="{{image}}" /></a>',
    });
    feed.run();
</script>

The template is rendering but the data is absent:

<div id="instafeed">
        <a href=""><img src=""></a>
</div>

Any advice for troubleshooting this?

Thanks.

@stevenschobert
Copy link
Owner

Are you hosting your site on shopify, Jekyll or some other system that uses curly braces for templating?

@PhilRedm
Copy link
Author

Yep. I'm using Craft CMS with Twig templates. Do I need to escape the curly braces somehow?

@stevenschobert
Copy link
Owner

Yes, you'll want to assign your template to a twig variable using set:

{%set instafeed_template = '<a href="{{link}}"><img src="{{image}}" /></a>' %}

// further down your page
var feed = new Instafeed({
  template: "{{instafeed_template}}"
  // other settings
});

Twig docs: http://twig.sensiolabs.org/doc/tags/set.html#set

See #41 for related issues.

@PhilRedm
Copy link
Author

That worked with the modification of adding js output escaping tags in Twig like so:

{%set instafeed_template = '<a href="{{link}}"><img src="{{image}}" /></a>' %}

{% autoescape 'js' %}
<script type="text/javascript">
    var feed = new Instafeed({
        get: 'user',
        userId: '180XXXXXX2',
                target: 'instafeed',
                clientId: '9930blahblahbalhetc9ff',
        limit: 10,
        template: '{{instafeed_template}}'
    });
    feed.run();
</script>
{% endautoescape %}

Without the autoescaping the code block renders as a quoted string.
Thanks for your excellent support!

@stevenschobert
Copy link
Owner

Ah, sorry about that, I wasn't aware that extra directive was needed!

Thanks for taking the time to go back and update this issue so other people can benefit from it!

@alexpriceco
Copy link

alexpriceco commented Jul 18, 2016

If you're working with Jekyll, as I was, you'll use:

{% raw %}
<script type="text/javascript">
    var feed = new Instafeed({
        get: 'user',
        userId: '180XXXXXX2',
                target: 'instafeed',
                clientId: '9930blahblahbalhetc9ff',
        limit: 10,
        template: '<img src="{{image}}" />'
    });
    feed.run();
</script>
{% endraw %}

@simran2017
Copy link

simran2017 commented Jan 11, 2018

How can we show video with play button, i am using default version of instafeed and it shows both image & videos but user gets confused as all items look like videos so i want to put play icon on top of those images whcih actually are images https://codepen.io/anon/pen/eyMpMQ for example in this example 6th items is video

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants