3 ms·
Here's what this would look like in Forward: <table> {foreach "/accounts"|get as $user} <tr class="{cycle values="odd, even"}"> <td class
by ericingram 14y ago
Here'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?
- ericingram 14y agoThe whole framework is very small, so yeah it would be easy to separate.