Why this works: Meteor-Blaze #with and data context? -


i wonder why following thing outputs 'hello' instead of 'bye'???

template:

<template name="example">     {{#with datacontext}}         {{say}}     {{/with}} </template> 

template helper:

template.example.helpers({     datacontext: function() {         return {             say: 'bye'         };     },     say: function() {         return 'hello';     } }); 

(meteor 1.1.0.2)

the shortest answer helpers have preference on data context.

if rename 1 of them else should solve problem.

the order lookup goes is:

  1. the data context (if contains .). {{say}} not.
  2. the template's helper. {{say}} has helper say.
  3. a template
  4. a global helper such defined template.registerhelper.
  5. the data context

so if first isn't found, goes down list until finds something

[1]https://github.com/meteor/meteor/blob/90b356061ff2464f11749dc8b43d1a139b233980/packages/blaze/lookup.js#l100-l139


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -