FYI: Changing Template Content Based on being on Security/login page or not...

silverstripe-3
Tags: #<Tag:0x00007f0843a29f70>

#1

I wanted to alter the page layout based on whether or not the active page was ‘Security/login’.

This is what we did to solve the issue of determining if the current page is the Security/login page or not. We placed the following code into the page controller:

public function IsLoginFormPage() {
        $controllerSitetree = Director::get_current_page();
        if($controllerSitetree instanceof Security){
            $activePage = $controllerSitetree->getRequest()->getURL();
            if($activePage === "Security/login"){
                return true;
            }
        }
        return false;
    }

and this in the template:

<% if $IsLoginFormPage %>
            $LoginForm
        <% else %>
            <div class="col-md-12">
                <div class="video">    
                    <span class="video-height"></span>    
                    <iframe src="https://www.youtube.com/embed/i57tTJ0hPe8?autoplay=1&showinfo=0&controls=0&modestbranding=1&rel=0" frameborder="0"></iframe>
                </div>
            </div>
            <% include SignupForm %>
        <% end_if %>

That enabled us to embed our video (YouTube) with modest branding and autoplay on if the page was not the login page.

Also had this suggestion given to me after the fact, which has pros and cons compared to my solution:

The solution was to create and not properly namespace Security_login.ss in my theme.

In the Security_login.ss file does not use Template namespacing and you use $Form rather than $LoginForm where you want the form to be embedded in the template.