gobuffalo / plush

The powerful template system that Go needs
MIT License
895 stars 57 forks source link

Allow contentOf helper to have a default value #57

Closed stanislas-m closed 6 years ago

stanislas-m commented 6 years ago

Before v3.7.4, the contentOf helper behavior was to fallback silently on empty string, if a content was not provided for the named block.

A typical usage for this fallback behavior was to override a block, just if needed: for instance, I want to define a custom style section in my HTML page, but if the contentFor the style section is not provided, I just want to fallback with a blank line.

I like the fact the behavior is now more rigorous, that's a good thing to know your block is not set properly. The good approach here (in my opinion) is to allow contentFor to accept a default block content. If this default block is not provided, then it can go the error state.

<%= contentOf("buttons") %>
<%= contentOf("buttons", {"label": "Click me"}) %>
<%= contentOf("buttons") { %>A default fallback value<% } %>

Thoughts?

ruudk commented 6 years ago

Fixed in https://github.com/gobuffalo/plush/pull/61