0

I have a template that looks like this. It used to work with regular html file, however, it is not working now.

This is my test.html file.

<template name="test">
<a href="xxxxxxxx" class="screenshot">
    <img src="xxxxxx" alt="Screenshot" class="thumbnail"/>
    <span class="screenshot-zoom"></span>
</a>
<script>
    $(function () {
        $(".screenshot").lightbox();
    });
</script>
</template>

EDIT1

I follow https://stackoverflow.com/a/10119993/772481 and try similar test, but still not working.

->test.html
<template name="test">
    <a href="./img/screenshots/placeholder.gif" class="screenshot">
        <img src="http://placehold.it/300x120" alt="Screenshot" class="thumbnail"/>
        <span class="screenshot-zoom"></span>
        {{add_my_special_behavior}}
    </a>
</template>

->screenshot.js
Template.test.add_my_special_behavior = function () {
    Meteor.defer(function () {
        // do stuff to it
        $(".screenshot").lightbox();
    });
    // return nothing
};
Community
  • 1
  • 1
angelokh
  • 9,426
  • 9
  • 69
  • 139

1 Answers1

1

Use the rendered event available to your template:

Template.test.rendered = function() {
  $(".screenshot").lightbox();
}

This will execute the lightbox method after Meteor has rendered the template.

Rahul
  • 12,181
  • 5
  • 43
  • 64