Different themes

During runtime based on a decision made in a microflow checking user roles, how do you set different themes? For instance, when logging in as an Administrator, see a theme (i.e. red menu bar with admin logo). When logging in as a User see a different theme automatically (i.e. green menu bar with user logo). p.s the themes must change on login.
3 answers

In order to add the names of the current user's user roles to the body, you could use this script. It should be added right below the inclusion of mendix.js.

<script type="text/javascript">
    (function() {
        var classes = [];

        dojo.connect(mx.ui, "startup", function() {
            dojo.addOnLoad(function() {
                var roles = mx.session.getUserRoles("Name");

                for (var i = 0, role; role = roles[i++];) {
                    var claz = "role-" + role.toLowerCase();
                    dojo.addClass(document.body, claz);

        dojo.connect(mx, "logout", function() {
            for (var i = 0, claz; claz = classes.pop();) {
                dojo.removeClass(document.body, claz);

This will add all user role names to the body (in lowercase, and with a 'role-' prefix to distinguish it from theme classes). Then you could do user role specific things such as

.role-administrator .MxClient_headerPane {
    background-color: red;

Currently not possible without a proper custom widget. We are testing this for Mendix 3.0, the user role (ur_administrator e.g.) will be added to the body class. Feature request always helps.


See this question.