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.

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

$summary_fields with HTML?


Go to End
Reply


6 Posts   1127 Views

Avatar
Bereusei

Community Member, 96 Posts

18 December 2013 at 8:52pm

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.

Avatar
Bereusei

Community Member, 96 Posts

19 December 2013 at 1:07am

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));

Avatar
Willr

Forum Moderator, 5521 Posts

23 December 2013 at 11:27am

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'
)

Avatar
Tama

Community Member, 138 Posts

3 March 2016 at 4:33pm

Casting only works if you can return a HTML object:

public function Icon(){
    $output = HTMLText::create(); 
    $output ->setValue('<i style="font-size:50px;" class="'.$this->IconCode.'"></i>'); 
    return $output;
  }

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

  private static $summary_fields = array(
    'Icon',
    'Heading',
    'Text'
    );

Hat tip to: http://sunnysideup.co.nz/

Avatar
zenmonkey

Community Member, 544 Posts

12 March 2016 at 5:07am

Sorry to necro this thread, but the tecnique no longer seems to work in SS3.3

Avatar
Gdog

Community Member, 1 Post

18 April 2016 at 9:35am

#zenmonkey I've just tested this technique in 3.3.1 & it works sweet.