Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » A way to add a filter to rendered page just before sending to browser

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

Page: 1
Go to End
Author Topic: 894 Views
  • micschk
    Avatar
    Community Member
    19 Posts

    A way to add a filter to rendered page just before sending to browser Link to this post

    Is there a way to add/hook into an [onbeforeOutputToBrowser] kind of filter in Silverstripe, like the onafter filters for writing to the database?

    I'm trying to rewrite all references to youtube.com into youtube-nocookie.com to prevent 3rd party cookies from being set. Most of these are oembeds, which are rendered from the SSViewer (I think), at least after the init() or index() functions are called. So I cannot do a str_replace in there. Maybe I could hook into the SSviewer in some way just before output?

    Maybe some way to hook into RequestProcessor->setFilters() ?

    [Got this filter idea from WP; see for example http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content ]

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: A way to add a filter to rendered page just before sending to browser Link to this post

    I'm assuming here that you're trying to filter the "same part" of the page that you would be filtering with WordPress the_content filter.

    So one way of doing this is simply writing a custom filter function and calling that in your template instead of $Content.
    So

    function FilteredContent() {
    $content = $this->Content;
    //Do your filtering here...
    return $content;
    }

    That goes into your page class or whatever other page type you want to do the filtering in.
    Then in your template you simply write $FilteredContent instad of $Content and you should be good to go.

    894 Views
Page: 1
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.