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.

Widgets

Discuss SilverStripe Widgets.

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

Widget theming - new & improved in version 2.3


Reply

2 Posts   1560 Views

Avatar
Hamish

17 December 2008 at 8:28am (Last edited: 17 December 2008 8:29am), Community Member, 712 Posts

Hi all,

A new innovation in version 2.3 (in RC2 now) has particular benefits to Widget developers.

You can now set themed CSS requirements from within a template with the tag:

<% require themedCSS(MyCssFile) %>

Why is this so great?

To style your widget in previous versions you had to call [url=http://api.silverstripe.com/default/Requirements.html#themedCSS]Requirements::themedCSS[/url]. This had to happen from somewhere in the Widget class when a piece of viewable data was requested. Since you never know if some designer is going to modify your widget template, you really should have been calling this for every field.

Now you can just place that tag at the beginning of your Widget template (.SS) file and let SilverStripe do the hard work! It saves you time and should execute quicker.

Regards,
Hamish

Avatar
simon_w

17 December 2008 at 5:55pm Forum Moderator, 474 Posts

You could put the Requirements call in WidgetHolder, then return parent::WidgetHolder() (return nothing from the method and the widget wont display, handy for admin only widgets), which would get called when it gets rendered.

But this is far better, and less confusing, way to add in Requirements. If I recall correctly, you can do the same with <% require javascript(file) %>, thus ensuring that all your JS is included in the correct order, without overriding WidgetHolder().