Jump to:

3434 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Check environment type within within templates

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

Page: 1
Go to End
Author Topic: 1269 Views
  • johannes
    Avatar
    Community Member
    20 Posts

    Check environment type within within templates Link to this post

    I included a tracking script at the bottom of my Page.ss, like this:

    <% if CurrentMember %>
    <% else %>
    <% if URLSegment != Security %>
    <% include TrackingCode %>
    <% end_if %>
    <% end_if %>

    To avoid the tracking of editors I wrapped it up with the login check. Everything works great, but when I'm on my local dev copy the script gets included again, tracking me....

    So my question is if there is a way to check the environment type within the template, or do I have to put everything into the Page_Controller?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Check environment type within within templates Link to this post

    I don't believe any template controls are built in for it. The function I use is trivially simple

    function IsLive() {
    return Director::isLive();
    }

    Then in the template <% if IsLive %>

  • johannes
    Avatar
    Community Member
    20 Posts

    Re: Check environment type within within templates Link to this post

    This is brilliant, thank you!

    1269 Views
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.