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

12 Posts   2040 Views


20 October 2010 at 6:04am Community Member, 51 Posts

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

<% if BaseHref != "" %>
<% 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.




20 October 2010 at 6:18am Community Member, 94 Posts

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


20 October 2010 at 6:26am Community Member, 51 Posts

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.



20 October 2010 at 8:39am (Last edited: 20 October 2010 8:39am), Community Member, 94 Posts

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() == '');


20 October 2010 at 11:02pm Community Member, 51 Posts

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');


20 October 2010 at 11:15pm Forum Moderator, 1796 Posts

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


20 October 2010 at 11:20pm Community Member, 51 Posts

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?


20 October 2010 at 11:24pm Forum Moderator, 1796 Posts

"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