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.

Template Questions /

Syntax problem in IF control


Go to End
Reply


12 Posts   2132 Views

Avatar
J2-Paul

Community Member, 51 Posts

20 October 2010 at 6:04am

Here is my code...which is not working.

<% if BaseHref != "http://subdomain.ourdevserver.net/" %>
<% include GoogleAnalytics %>
<% end_if %>

I am fairly certain it is the / and : and . chars causing the issue. However, I am not good enought yet to figure out how.

I have tried using the XML_val method but to no avail.

Any assistance on syntax would be very much appreciated.

Thanks

Paul

Avatar
bartvanirsel

Community Member, 94 Posts

20 October 2010 at 6:18am

Hi Paul, im not sure but i think the BaseHref var is not the domian but relative to it.

Avatar
J2-Paul

Community Member, 51 Posts

20 October 2010 at 6:26am

No, it is the value I need to query. I have placed in the the template and it spits out a value in the structure I use in my example code.

"http://subdomain.ourdevserver.net/"

Avatar
bartvanirsel

Community Member, 94 Posts

20 October 2010 at 8:39am

Edited: 20/10/2010 8:39am

ok, then i was wrong.

i looked it up in some of our templates and this works in one of our sites:

<% if ClassName != "GardenHolder" %>

i think you are right about the / or : char
advise is to do a workaround maybe?
Creating a CheckBaseHref method in the Page class which checks the base_href

something like

function checkBaseUrl() {
return (Director::absoluteBaseURL() == 'http://subdomain.ourdevserver.net/');
}

Avatar
J2-Paul

Community Member, 51 Posts

20 October 2010 at 11:02pm

Thanks Bart. I had this idea as well, was just trying to make it as compact as possible.

One further question, can we refer to the setting in _config.php "Director::set_environment_type("dev");"

If so, then this function can be configured to work independently from the site base url.

Something like.

function checkIfLive() {
return (Director::set_environment_type == 'dev');
}

Avatar
swaiba

Forum Moderator, 1804 Posts

20 October 2010 at 11:15pm

btw I don't think you should use quotes in <% if %> statements in the templates

Avatar
J2-Paul

Community Member, 51 Posts

20 October 2010 at 11:20pm

Really. I do it quite a bit and it works OK when the are no "special" characters in the string.

Why should they not be used?

Avatar
swaiba

Forum Moderator, 1804 Posts

20 October 2010 at 11:24pm

http://doc.silverstripe.org/templates#if_blocks

"You should not include quotes around the value."

As for the why... that would be a ss developer who would answer... but I'd have a guess it is about simplicity in the templates...

Go to Top