Accessing helpers in content blocks

Am I wrong to think content blocks can be used in this way?

You need to understand more fully the idea of which template you are actually in, currently.

And this is easy to do, though not immediately intuitive:

No matter what block helper you are calling, like #if or #myOwnBlockHelper, it doesn’t change what your current template is. Otherwise just calling a single #if would mess up all of your template code.

This means that as long as what you’re writing is contained within e.g.

<template name="myTemplate">

you are always in the (data) context of myTemplate.

<template name="myTemplate">
    Still works:

  myTemplateVar1: function() { return "myTemplateVar1" })

<template name="myBlockHelper">
  This one will not be found:
  But this template has its own vars:

  myBlockHelperVar1: function() { return "myBlockHelperVar1" })
1 Like

So in short content blocks don’t affect context at all? Only template does? It helps to understand that “if” is just a block helper and it doesn’t make sense that it changes the data context.


Exactly, I think the only block helpers that do change context are with and each. All others keep you in the context of the current template / the one you were in before (or rather outside) the block helper.
And I don’t know if we understood each other about the if block helper – yes, it does not change the data context. Same context outside and inside the if construct.