5 ms·
I can't stand mustache and handlebars. Why do you dislike them? Separation of design and code seems pretty important, so having a template system that's reall
by randallsquared 14y ago
I can't stand mustache and handlebars.
Why do you dislike them?
Separation of design and code seems pretty important, so having a template system that's really a (more or less limited) programming language of its own seems like a step backward to me.
- ericingram 14y agoI thought about this a lot, believe me. Is it right to allow a template to have so much control? The side effect of not having it is, designers can't do anything without a back-end programmer. Instead, Forward aims to make templates expressive and easy to understand by anyone. Time will tell if this causes problems, but for the projects we've built with it over the last year, it has been good and easy to maintain as there is no procedural connection between template/back-end.
- whalesalad 14y agoHonestly the django/jinja syntax and library of helpers/filters is virtually impossible to beat. ### Example User user: { name: "Michael", bio: "The quick brown fox jumped over the lazy dog.", products: [<Product>, <Product>, ... ] joined: "09-07-12" } <table> {% for user in users %} <tr class="{% cycle 'odd' 'even' %}"> <td class="user-name">{{ user.name }}</td> <td class="user-bio">{{ user.bio|truncatewords:3 }}</td> <td class="user-products">{{ user.products.count }} Product{{ user.products.count|pluralize }}</td> <td class="user-joined">{{ user.joined|date:"M jS, Y" }}</td> </tr> {% endfor %} </table> ### Would Display <tr class="odd"> <td class="user-name">Michael</td> <td class="user-bio">The quick brown ...</td> <td class="user-products">2 Products</td> <td class="user-joined">September 7th, 2012</td> </tr>
- ericingram 14y agoHere's what this would look like in Forward: <table> {foreach "/accounts"|get as $user} <tr class="{cycle values="odd, even"}"> <td class="user-name">{$user.name}</td> <td class="user-bio">{$user.bio|truncate:30}</td> <td class="user-products">{pluralize "{$user.products.count} Products"}</td> <td class="user-joined">{"M jS, Y"|date:$user.date_created}</td> </tr> {/foreach} </table>
- whalesalad 14y agobeautiful. stoked to start playing with it.
- mikelbring 14y agoSo is that like hitting an API endpoint? `"/accounts"|get` makes it feel like it. Pretty neat.
- ericingram 14y agoRe: API endpoint, that's exactly it. Here are several equivalent ways of expressing this: // PHP $accounts = get("/accounts"); // Template {get $accounts from "/accounts"} {$accounts = get("/accounts")} {$accounts = "/accounts"|get} Here's a really cool side effect of the way the model result works... {$account = "/accounts/123"|get} {put [role => "admin"] in $account} When converted to a string, they represent a model URI.
- ricardobeat 14y ago{put [role => "admin"] in $account} Does this mean you have all your view logic inside the templates?
- ericingram 14y agoGenerally logic that is good in a controller can be put in the template file instead. This idea came from the "Smart model, Dumb controller" concept. We made controllers so dumb, it was rather clean and easy to understand when combined with a template. We see more of this with client side frameworks like Meteor. Still, Forward is built on a new micro MVC framework and controllers do still exist. Those that prefer to write them can do so in a more traditional way. class AccountController extends Controller { function index () { $this->account = get("/accounts/123"); put($this->account, [role => "admin"]); } } (This is not very useful code but you get the idea)
- laktek 14y agoAny plans to release the template engine as a standalone package?
- nahname 14y agoThat looks exactly like every other web templating view engine. You are also completely missing the point if you think client side templates are trying to replace your web frameworks. Client side templates are supposed to emulate what you have server side when you to deal with data client side.