794 Posts in 408 Topics by 304 members
|Go to End|
4 April 2014 at 1:11am
In Admin I have a widget that I only want to be available on a certain pagetype. I've tried things like the code below, but can't get it to work.
class MyWidget extends Widget
static $only_available_in = array('MyPageType');
// More stuff etc.
Can anyone help?
4 April 2014 at 5:06pm
$only_available_in looks to be what you want (https://github.com/silverstripe/silverstripe-widgets/blob/master/code/model/Widget.php#L30) I would check to ensure you have marked it as private, got the latest version of widgets module and you've done a flush.
4 April 2014 at 9:10pm
I've tried your suggestions and it's still not working. Basically the widget doesn't appear in the available widgets area when I add that line of code (and I've doubled checked I am on a page with the correct pagetype).
My set up is as follows. I have a pagetype that extends Page, called PageHolder. My widget allows you to list child pages in the widget area. The bare bones of my widget code is as follows:
class PageHolderListPlacementWidget extends Widget
static $cmsTitle = 'Page Holder List Placement Widget';
static $description = 'This widget allows you to position a Page Holder list on the page.';
private static $only_available_in = array('PageHolder');
// The rest of my widget code...
Let me know if you think of anything else?
|Go to Top|