Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Honestly 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>


That 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.


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>


Re: 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.


    {put [role => "admin"] in $account}
Does this mean you have all your view logic inside the templates?


Generally 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)


So is that like hitting an API endpoint? `"/accounts"|get` makes it feel like it. Pretty neat.


Any plans to release the template engine as a standalone package?


The whole framework is very small, so yeah it would be easy to separate.


beautiful. stoked to start playing with it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: