How to catch Error: No such template: myTemplate?

Hi,

I am building an app which dynamically creates templates in the router. Does anyone know where I can put the try/catch in order to get this error? I’ve tried wrapping the render() call but it happens much later (in Blaze, I think). For example:

<h1>Example</h1>
<p>This is an example template source which loads another template<p>
{{> myOtherTemplate}}
<p>End of example template</p>

When this template renders it throws

Error: No such template: robs
    at Blaze.View.lookup (lookup.js:122)
    at null.<anonymous> (spacebars-runtime.js:30)
    at view.js:191
    at Function.Template._withTemplateInstanceFunc (template.js:437)
    at view.js:190
    at Object.Blaze._withCurrentView (view.js:523)
    at viewAutorun (view.js:189)
    at Tracker.Computation._compute (tracker.js:294)
    at new Tracker.Computation (tracker.js:210)
    at Object.Tracker.autorun (tracker.js:533)

Thanks
Rob

You could use {{> Template.dynamic myTemplate}} and then only call it if Template[myTemplate] is defined?

1 Like