Search code examples
javascriptangularjstemplate-enginesecurity-roles

Client Side Template with view per role


I've been reading about AngularJS and it seems very promising, the only thing I'm trying to figure out, not specific for framework, but it's general for client-side template.

Let's say you have a web application with multiple roles, each role may contain addition feature,,, so you cannot have different template for each role, that would be considered bad practice, so my question is what's the best approach to use client-side template in the mean time, not exposing your template to client, so for example, in AngularJS I don't have to use ng-show? What best tool to generate template at server side?


Solution

  • Blesh is correct about only providing data to users with the appropriate role on the server side, but it sounds like you want to re-use pieces of your client UI.

    In AngularJS, you could use ng-include and build up different partials for different pieces of data. So you could write something like this in both your "doctor" and "nurse" views:

    <div ng-include="'allergies.html'"></div>
    

    And then have a separate HTML file called allergies.html:

    <p>Allergy info: {{someData}}</p>
    

    Another option would be to use directives.