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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Lots of empty lines inserted into html?


Go to End


13 Posts   7288 Views

Avatar
swaiba

Forum Moderator, 1899 Posts

16 February 2011 at 12:41am

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

Community Member, 197 Posts

16 February 2011 at 1:33am

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

Forum Moderator, 1899 Posts

16 February 2011 at 1:37am

how about...

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

instead of...

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

Avatar
DeklinKelly

Community Member, 197 Posts

16 February 2011 at 2:12am

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

Forum Moderator, 1899 Posts

16 February 2011 at 2:32am

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

Go to Top