0

My question is very simple but I didn't find the exact answer.

<template name="loading">
//loading spineer
</template>

Now I need to hide and show this template with subscription ready. How do I render loading template from javascript. I have tried

{{#unless Template.subscriptionsReady}}
 {{> loading}}
{{/unless}}

and

{{#If Template.subscriptionsReady}}
 {{> loading}}
{{else}}
 content
{{/if}}

But in my case #unless and #if is not required. Have to load it from script.

1
  • @DavidWeldon. Yes, I mean #unless and #if is not my requirement. have to show/hide loading template from script. Commented Nov 25, 2015 at 6:20

3 Answers 3

1

You can render a Template from JS with the Blaze.render() or Blaze.renderWithData() function.

The official meteor documentation describes how to use it
http://docs.meteor.com/#/full/blaze_render

Example:

// This will render your template to the body and remove it after 3000ms

var view = Blaze.render(Template.loading, document.getElementsByTagName('body')[0]);
setTimeout(function() { Blaze.remove(view) }, 3000);
Sign up to request clarification or add additional context in comments.

Comments

0

Very simple. Check out Spacebars built off of Handlebars.

{{#if Template.subscriptionsReady}}
  {{> notLoading}}
{{else}}
 {{> loading}}
{{/if}}

1 Comment

#unless and #if is not my requirement. How to render it from script
0

You can load a template from javascript by suing Blaze.render. In your html, create a div and assign it a id, say "rendertemplatehere".

HTML:

<div id="rendertemplatehere"></div>

In javascript, after writing logic, whenever you want to render template, after your subscription is ready, execute,

Javascript:(Help from webdeb's answer to same question)

    var view = Blaze.render(Template.loading, document.getElementById('rendertemplatehere'));

And, if you want to remove the template (if its already rendered), when your subscription expires/is not ready, execute,

Javascript:

Blaze.remove(view);

4 Comments

your way of removing is totally wrong.. take a look at the docs dude, what is if render it to body???
@webdeb Edited the answer, do you think it's fine ?
Just saw your answer to same question, and used your way of storing the view while rendering the template. Thanks for the help, and any other advise? Also, do you think it's fine now?
yes, now it would work like expected.. but the best way to prove it, test it ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.