Jump to:

3447 Posts in 1032 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » Custom Login Template depending on Viewer Group

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 656 Views
  • spierala
    Community Member
    80 Posts

    Custom Login Template depending on Viewer Group Link to this post

    Hello all,
    I want to show custom Login Templates for admins and clients trying to log in on the site.
    Therefore I would have to know to which Viewer Group that page belongs (client or admin).

    I have already the basic setup to perform a switch...
    I have a custom loginform (CustomLoginForm.php) class, which I enabled using this in config.php:

    Object::useCustomClass('MemberLoginForm', 'CustomLoginForm');

    To use a custom template for the login form you just have to put a file named "Security_login.ss" in the Layout folder.
    So far so good.
    In CustomLoginForm.php I want to check the Viewer Group of the visited page with a function.
    But I do not know how to get that info. So far I can access $_REQUEST['BackURL'], which is /admin or /client/something.
    I could to the switch on that BackURL, but that doesn´t seem to be a cool solution

    Does anyone know better?
    Many thanks,

  • rob.s
    Community Member
    78 Posts

    Re: Custom Login Template depending on Viewer Group Link to this post


    perhaps the following approaches work for you:

    Inside your Form

    1. Get the instance of the current controller and check the className:

    $cont = Controller::curr();
    if( $cont instanceof YourPageType_Controller ) {
    // do this
    } else {
    //do that

    2. evaluate the ViewerGroups of the current controller (the security groups that have access to the controller)

    $cont = Controller::curr();
    $groups = $cont->ViewerGroups(); // this is basically a many_many component set

    Does this help?


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.