Jump to:

23358 Posts in 17873 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » $summary_fields with 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
Go to End
Author Topic: 264 Views
  • Bereusei
    Avatar
    Community Member
    94 Posts

    $summary_fields with HTML? Link to this post

    Hey guys,

    Is it possible to display HTML content in $summary_fields?

    static $summary_fields = array(
    'Title' => 'Title,
    'myHTMLString' => 'HTML String'
    );

    public function myHTMLString(){
    return "Lorum ipsum <table><tr><td>Blabla</td></tr></table>";
    }

    If I do it that way, I get the HTML elements back as string.

  • Bereusei
    Avatar
    Community Member
    94 Posts

    Re: $summary_fields with HTML? Link to this post

    Found a solution. Not very nice, but it works for me:

    Add "htmlspecialchars_decode" in frameworks/forms/gridfield/GridField.php line 353:

    $rowContent .= FormField::create_tag('td', $colAttributes, htmlspecialchars_decode($colContent));

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: $summary_fields with HTML? Link to this post

    You can use setFieldFormatting (e.g https://github.com/silverstripe/silverstripe-comments/commit/6de470125b4fe2058a59a47a87f83bc89fb27f07) to override formatting for a column value. Perhaps also try adding your custom summary field to the $casting array, I wonder if GridField picks up the objects casting

    private static $casting = array(
    'MyField' => 'HTMLText'
    );

    private static $summary_fields = array(
    'MyField'
    )

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