Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requesting HelpHelper / @Html.Checkbox etc #57

Open
alexellis opened this issue Mar 10, 2015 · 5 comments
Open

Requesting HelpHelper / @Html.Checkbox etc #57

alexellis opened this issue Mar 10, 2015 · 5 comments

Comments

@alexellis
Copy link

Hi,

One of the nice features of Razor is the @html helper for CheckboxFor etc..

Would you consider implementing a basic / initial version of this?

Thanks

@kirbysayshi
Copy link
Owner

I probably won't (vash's api is alread larger than I want it to be), but the helper system is meant to be extensible by developers. If you attach a function to vash.helpers, it will be accessible within the executing template context.

@alexellis
Copy link
Author

Can you give an example please? Also is Vash still being maintained and developed?

@kirbysayshi
Copy link
Owner

yes, vash is still being maintained. Development has slowed down though, mostly because it's relatively stable and the needs of the community, in general, are moving towards things like React.

It's been awhile since I used actual ASP MVC, but I believe this would do what you want (client side usage is similar, but I'm not sure how you're deploying/executing code):

var helpers = require('vash/runtime').helpers;
helpers.CheckboxFor = function(checked, attributes) {
  this.buffer.push('<input type="checkbox" ' + (checked ? 'checked' : '')
    + Object.keys(attributes).map(function(attribute) {
      return attribute + '=' + this.escape(attributes[attribute]);
    }).join(' ')
    + '>'
  ); 
}

You can also use a compiled helper, or use a function that returns a string. The choice is up to you, depending on your needs.

@alexellis
Copy link
Author

I will try this out. I didn't understand the reference to React though - having tried it briefly in a hackathon event it does not seem to make any sense for node.js templating at the server-side. The benefits of a 'virtual dom' don't really seem to exist.

It would be great to think vash could continue to be supported through future versions of node etc. Failing that - handlebars seems to be very limited in comparison (particularly when it comes to conditional statements) - perhaps people would migrate to EJS?

@kirbysayshi
Copy link
Owner

Don't worry, I'll continue to support vash! I'm not keen on adding to the API / maintenance too much though, because it's already a relatively large project in terms of API surface area. So if you'd like helpers and things, it's probably best to create a separate package for those that you require in your app.

What I meant about react is that it's a very stable templating solution that can use the templates on both the server and client. While you're right that a virtual dom isn't useful on the server, the main benefit is actually just the large community around JSX: tools, syntax highlighting, etc. It's pretty easy to take a React component and render it to a string: https://facebook.github.io/react/docs/top-level-api.html#reactdomserver.rendertostring.

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

No branches or pull requests

2 participants