Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Check environment type within within templates


Go to End


3 Posts   3103 Views

Avatar
johannes

Community Member, 20 Posts

27 July 2010 at 8:44am

Edited: 27/07/2010 8:44am

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?

Avatar
Willr

Forum Moderator, 5523 Posts

27 July 2010 at 11:37am

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 %>

Avatar
johannes

Community Member, 20 Posts

27 July 2010 at 7:55pm

This is brilliant, thank you!