Jump to:

794 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » In Admin Only Show Widget on Certain Pagetypes

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 624 Views
  • _Matt
    Avatar
    Community Member
    25 Posts

    In Admin Only Show Widget on Certain Pagetypes Link to this post

    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.

    <?php

    class MyWidget extends Widget
    {
    // Stuff

    static $only_available_in = array('MyPageType');

    // More stuff etc.

    Can anyone help?

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: In Admin Only Show Widget on Certain Pagetypes Link to this post

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

  • _Matt
    Avatar
    Community Member
    25 Posts

    Re: In Admin Only Show Widget on Certain Pagetypes Link to this post

    Thanks Willr.

    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:

    <?php

    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?

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