21487 Posts in 5783 Topics by 2621 members
| Go to End | ||
| Author | Topic: | 1821 Views |
-
Re: Lots of empty lines inserted into html?

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
-
Re: Lots of empty lines inserted into html?

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 -
Re: Lots of empty lines inserted into html?

16 February 2011 at 1:37am
how about...
Object::add_extension('Page_Controller','ZapWhitespace');
instead of...
Object::add_extension('SiteTree', 'ZapWhitespace');
-
Re: Lots of empty lines inserted into html?

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;
}
}?>
-
Re: Lots of empty lines inserted into html?

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;
}
...
}
| 1821 Views | ||
| Go to Top |


