Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Dynamic Helper #24

Closed
adithep opened this issue Apr 15, 2014 · 3 comments
Closed

Dynamic Helper #24

adithep opened this issue Apr 15, 2014 · 3 comments

Comments

@adithep
Copy link

adithep commented Apr 15, 2014

Hey I am sorry if I might me doing this wrong but I have been trying to get dynamic helper to work.

What I am doing is have a helper named attrs return an object {type: 'text', placeholder: 'hello'}

to the template that has input($dyn = attrs)

If this is not the way to use dynamic template, please point me to the right way.

@mquandalle mquandalle added the bug label Apr 15, 2014
@mquandalle
Copy link
Owner

@dgreensp This is a bug with the $specials field. The compiler seems to expect this field to be an array (in the AST) and it doesn't work with a non-array value. This behavior is inconsistent with the other constructors.

// First case: $specials value wrapped in an array
Spacebars.codeGen(HTML.P({
  "$specials": [
    HTMLTools.Special(Spacebars.TemplateTag.parse('{{xxx}}'))
  ]
}));

// This works as expected and returns
'(function() {
  var self = this;
  return HTML.P({
    $dynamic: [ function() {
      return Spacebars.mustache(self.lookup("xxx"));
    } ]
  });
})'


// Second case: $specials value NOT wrapped in an array
Spacebars.codeGen(HTML.P({
  "$specials": HTMLTools.Special(Spacebars.TemplateTag.parse('{{xxx}}'))
}));

// returns
'(function() {
  var self = this;
  return HTML.P();
})'

// instead of
'(function() {
  var self = this;
  return HTML.P({
    $dynamic: function() {
      return Spacebars.mustache(self.lookup("xxx"));
    }
  });
})'

BTW I think that the array optimization (ie don't use an array if there is only one value and merge consecutive strings) should be done by the compiler.

@epaminond
Copy link

Hi! I still have an issue. I try to pass attributes to div: .post($dyn=attributes), where attributes are {class: "post animate", style: "top: 0px"}. But I get an error:

Error: Illegal HTML attribute name: 0

The error is thrown by extendAttrs function, which gets string "[object Object]", as src argument instead of an actual object. This seems to be done by Spacebars.mustache function.

@mquandalle
Copy link
Owner

This is be fixed in the blaze-refactor branch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants