Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » Syntax problem in IF control

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

Page: 1 2
Go to End
Author Topic: 2000 Views
  • J2-Paul
    Avatar
    Community Member
    51 Posts

    Syntax problem in IF control Link to this post

    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

  • bartvanirsel
    Avatar
    Community Member
    94 Posts

    Re: Syntax problem in IF control Link to this post

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

  • J2-Paul
    Avatar
    Community Member
    51 Posts

    Re: Syntax problem in IF control Link to this post

    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/"

  • bartvanirsel
    Avatar
    Community Member
    94 Posts

    Re: Syntax problem in IF control Link to this post

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

  • J2-Paul
    Avatar
    Community Member
    51 Posts

    Re: Syntax problem in IF control Link to this post

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

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Syntax problem in IF control Link to this post

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

  • J2-Paul
    Avatar
    Community Member
    51 Posts

    Re: Syntax problem in IF control Link to this post

    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?

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Syntax problem in IF control Link to this post

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

    2000 Views
Page: 1 2
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.