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

Lots of empty lines inserted into html?


Reply

13 Posts   2896 Views

Avatar
swaiba

16 February 2011 at 12:41am Forum Moderator, 1796 Posts

I have not Deklin - I was hoping that you would do this as you asked for a way without hacking silverstripe and decorators often are that way - I am very interested to implement, but not interested enough to do it dev it just yet - as it's on my list for "mobile must be faster" in the future :)

Avatar
DeklinKelly

16 February 2011 at 1:33am Community Member, 197 Posts

I have tried to decorated the controller through a module but I don't have a clue what I am doing.

My code produces an error:
[Notice] Trying to get property of non-object

Attached Files
Avatar
swaiba

16 February 2011 at 1:37am Forum Moderator, 1796 Posts

how about...

Object::add_extension('Page_Controller','ZapWhitespace');

instead of...

Object::add_extension('SiteTree', 'ZapWhitespace');

Avatar
DeklinKelly

16 February 2011 at 2:12am Community Member, 197 Posts

Thanks, swaiba.

That got us closer but there is still an error:

[Notice] Trying to get property of non-object

<?php

class ZapWhitespace extends Extension {

   public function ZapWhitespace() {
      $str = $this->owner->value;
      $str = '<!-- Test-->'.preg_replace("/(?=\s\s)\s*?(\n)\s*|(\s)\s+/", "$1$2", trim($str)) . '<!-- Test-->';
      return $str;
   }
}

?>

Attached Files
Avatar
swaiba

16 February 2011 at 2:32am Forum Moderator, 1796 Posts

right... this might be a little simpler :)
(note I haven't tried it with the regular expression - I don't use them unless I FULLY understand them - but I have tested that this gets you access to the body :) )

in your Page.php

class Page_Controller extends ContentController {
...
   public function handleRequest(SS_HTTPRequest $request) {
      $ret = parent::handleRequest($request);
      $temp=$ret->getBody();
      $temp = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $temp);
      $ret->setBody($temp);
      return $ret;
   }
...
}