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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[Solved] $AbsoluteBaseURL or $BaseHref have CRLF appended


Reply

846 Views

Avatar
tazzydemon

7 March 2013 at 1:27pm (Last edited: 8 March 2013 5:34pm), Community Member, 122 Posts

I have been trying to make the ss3 dev site I am running in a subdirectory have correct template references by using this in my templates:

<script src="{$BaseHref?}{$ThemeDir?}/blahblah.js"></script>

or more correctly now:

<script src="{$AbsoluteBaseURL}{$ThemeDir?}/blahblah.js"></script>

However both fail because a PHP_EOL is being appended to the URL thus breaking the line and therefore the link.

I thought I had traced this to function Text__finalise() in SSTemplateParser.php.inc but this appears not to be the case. I thus far have failed to find the source. Note that the $ThemeDir? does not have the CRLF appended and the output directly from Director:absoluteBaseURL() seems fine.

Interesting that it's CRLF appended because I am testing on Windoze but serving from linux. The files are linux correct as far as I am aware.

Needless to say I have scoured the place for \r\n as well.

I have put this in Trac too.

Stop press. I tracked it to the casting in SSviewer using default casting (HTMLText) for the array in get_template_global_variables() in Director.php. I believe this should be 'Text' and I have altered the array in Director.php as follows:

   public static function get_template_global_variables() {
      return array(
         'absoluteBaseURL' => array('method' => 'absoluteBaseURL', 'casting' => 'Text'),
         'baseURL' => array('method' => 'baseURL', 'casting' => 'Text'),
         'is_ajax',
         'isAjax' => 'is_ajax',
         'BaseHref' => 'absoluteBaseURL', //@deprecated 3.0
      );
   }