George Katsanos
George Katsanos

Reputation: 14175

Architecture: Double views on the backend & frontend

I am building a webapp which uses AngularJS (or another JS MVC fw) and has its own templating language. At the same time, my back-end also has a template language, twig. I'm finding myself only having a general template/view in the backend and then doing everything with Angular... Does this mean my backend is too complicated/ I need something else?

Note that I do need user authentication..

Upvotes: 1

Views: 233

Answers (1)

Anders Ekdahl
Anders Ekdahl

Reputation: 22933

As long as your back-end rendering doesn't mix HTML with your data, back-end rendering is very useful. In our application we turn on/off functionality depending you licenses/permissions/etc, so we render different front-end templates depending on that. That makes our front-end code simpler since it has less things to deal with.

Let's say you have a list of tasks to display. You would handle the rendering of the task data on the client, but you might want to determine which columns that should be displayed on the server. Something like this:

<table>
    <thead>
        <tr>
        <?php foreach ($columns as $column) { ?>
            <th><?php echo $column->name; ?></th>
        <?php } ?>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="task in tasks">
        <?php foreach ($columns as $column) { ?>
            <td>{{<?php echo $column->property; ?>}}</td>
        <?php } ?>
        </tr>
    </tbody>
</table>

As longs as the templates your back-end is rendering are cacheable on the client, I'd say your fine.

Upvotes: 1

Related Questions