Skip to content

Custom block helper hides template instance #2923

@lbergnehr

Description

@lbergnehr

When assigning properties to a template instance in the created method of a template and a helper of that template is invoked inside a custom block helper, which is in turn invoked inside the actual template, the template instance of Template.instance() will be that of the custom block helper and not of the "real" template. For example, consider this:

<template name="templateBug">
  {{#contentBlockTemplate}}
    <span>{{notVisibleString}}</span>
  {{/contentBlockTemplate}}
</template>

and notVisibleString is using Template.instance() to access a property of the template instance; then that instance will be that of contentBlock and not templateBug, which to me is counter intuitive and makes it difficult to use a custom block helper with assigning properties to a template instance in Template.myTemplate.created.

Steps to reproduce

Example project which visualizes this here: https://github.com/lbergnehr/meteor_template_content_block_bug

git clone https://github.com/lbergnehr/meteor_template_content_block_bug.git
cd meteor_template_content_block_bug
git checkout with_content_block
meteor

this will not show the intended text, whereas removing the content block will:

git checkout without_content_block
meteor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions