I am looking for a way to be able to pass an object from Template.templateName.helpers to the html.
It seems that the syntax: {{objname.property}} does not work in spacebars.
How do I do it ?
Related
I am working on a template for a react component with plop.js and I am using conditional handlebars to render some content conditional upon an argument passed along with the command used to generate the content. Here is the conditional content of the template:
{{#ifCond "withStyles"}}import * as styles from "./{{pascalCase name}}.styles";{{/ifCond}}
When I use the line above, it returns "cannot read properties of undefined (reading "replace") which might be due to using {{pascalCase name}} inside the {{ifCond}} so how can we achieve the same thing in a correct way as it seems wrong.
Thanks in advance.
I need to collapse/expand a django-mptt list ideally using CSS (and no JavaScript) in my template:
Following guidance from http://django-mptt.github.io/django-mptt/templates.html, I got a basic view, and have consulted the below SO posts:
SO#6037469:show-children-nodes-depending-on-selected-parent only seems to work at the first hierarchical level(I'd prefer for this to be recursive down the list.
SO#26334107:expand-collapsible-list-of-objects threw an error:
Could not parse the remainder: '==0' from 'node.level==0'
Wonder if someone could please post an elegant CSS solution to templating such lists in a collapsible/expandable format?
Is there a way to check if a specific Template has been rendered, other than by using Sessions, i.e. the Template is accessible for other external functions to use?
A good example is that I want to use Blaze.renderWithData, but need to know that the Template is availabel beforehand.
If you want to see if a template has been rendered, put a flag in the onRendered callback. If you don't like Session vars use a reactive var or dict & include the inverse in the onDestroyed. Store that reactive-whatever under your package object's global. As an alternative, if you know where it might be rendered to, you can use Blaze.getView on the element where it should appear and if it returns, you know you have it, e.g. Blaze.getView($('.foo')[0])
Also consider asking yourself why you can't use spacebars or embed the rendering directly in the onRendered callback. Using Blaze.renderWithData is fairly uncommon.
In Meteor, if the below is my HTML,
<template name="myTemplate">
The value is {{value}}
</template>
I can define the value in two ways
Template.myTemplate.helpers
value: ->
'insideHelper1'
Template.myTemplate.value =
'outsideHelper1'
The first way is using helpers as documented here (http://docs.meteor.com/#template_helpers) whereas the second way is using the Live Template examples as defined here (http://docs.meteor.com/#livehtmltemplates)
Just wondering, what is the difference between the two and when should I use one over the other?
They're exactly the same.
If you use .helpers, it actually just adds it to Template..
It depends on your coding style. You may prefer to use .helpers since it makes cleaner code if you have many helpers on the same template.
One small technically way they're different is Template.helpers adds the helpers to your Meteor app when your Meteor app starts up, whereas using the Template.helpername adds it before. So if you need to overwrite any helpers, you could use the .helpers method. The one that runs last will have the active helper.
Is there a way to include an existing dom-element through Handlebars, while being able to keep a reference to said dom-element?
to explain:
I have a jquery-element $el of which I want to include the dom-element ($el[0]) in a handlebars template.
I have some jquery code that uses $el.html("new stuff") after handlebars has included the template (again: this template contains $el[0]
The usual solution would be to rewrite the code by providing a selector so jquery can access the element. However, the code that needs to change $el doesn't know where in the template $el[0] will be used, since this is configurable. Having to specify the selector by config is possible obviously but this doesn't really feel dry to me.
So, any way to do this?
I implemented this with a handlebars helper that injects a unique id and post-render keeps a ref from uniqueid -> element to bind.
On postrender I simply find the elements with the unique-ids and update each element to it's mapped el to bind.