Jump to:

22992 Posts in 11842 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Lots of empty lines inserted into html?

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

Page: 1 2
Go to End
Author Topic: 2313 Views
  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Lots of empty lines inserted into html? Link to this post

    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

  • DeklinKelly
    Avatar
    Community Member
    196 Posts

    Re: Lots of empty lines inserted into html? Link to this post

    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
  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Lots of empty lines inserted into html? Link to this post

    how about...

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

    instead of...

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

  • DeklinKelly
    Avatar
    Community Member
    196 Posts

    Re: Lots of empty lines inserted into html? Link to this post

    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
  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Lots of empty lines inserted into html? Link to this post

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

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