3217 Posts in 853 Topics by 812 members
| Go to End | Next > | |
| Author | Topic: | 1663 Views |
-
Syntax problem in IF control

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
-
Re: Syntax problem in IF control

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.
-
Re: Syntax problem in IF control

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/"
-
Re: Syntax problem in IF control

20 October 2010 at 8:39am Last edited: 20 October 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_hrefsomething like
function checkBaseUrl() {
return (Director::absoluteBaseURL() == 'http://subdomain.ourdevserver.net/');
} -
Re: Syntax problem in IF control

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');
} -
Re: Syntax problem in IF control

20 October 2010 at 11:15pm
btw I don't think you should use quotes in <% if %> statements in the templates
-
Re: Syntax problem in IF control

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?
-
Re: Syntax problem in IF control

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...
| 1663 Views | ||
| Go to Top | Next > |


