Jump to:

794 Posts in 409 Topics by 304 members


SilverStripe Forums » Widgets » My widget breaks silverstripe :(

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 685 Views
  • oscarw_89
    Community Member
    4 Posts

    My widget breaks silverstripe :( Link to this post


    I've made a widget for displaying some text and/or images.
    It seems to work just fine, except one big problem.
    It breaks the page .
    I don't get any error messages, but it ruins the layout. The page can't be viewed at all in Internet Explorer, the content is all over the place. But it's viewebal in Chrome & Firefox, but the whole page is moved down about 20px..

    I've compared my widget to other ones and I can't find what makes silverstripe behave so strange.



    class MyWidget extends Widget {
       static $db = array(
          "Title" => "Varchar",
          "Layout" => "Varchar",
          "SecondTitle" => "Varchar",
          "ImageCaption" => "Varchar",
          "Text" => "Text",
          "LinkUrl" => "Varchar",
          "ExtraLinkUrl" => "Varchar"
       static $has_one = array(
          'LinkImage' => 'Image',
          'ExtraLinkImage' => 'Image'
       static $has_many = array();
       static $many_many = array();
       static $belongs_many_many = array();
       static $defaults = array(
          "Title" => "",
          "Layout" => "Bluebox",
          "SecondTitle" => "",
          "ImageCaption" => "",
          "Text" => "",
          "LinkUrl" => "#",
          "ExtraLinkUrl" => "#"

       static $cmsTitle = "My Widget";
       static $description = "En widget för titlar, text, bilder, samt länkar.";
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $options = array("Bluebox" => "Bluebox", "ImageLink" => "ImageLink and text", "ImageLink2" => "ImageLink and text with extra ImageLink bellow text.");

             new FieldList(
                new TextField("Title", "Titel"),
             new DropdownField("Layout", "Layout (layouten 'bluebox' visar inga bilder)", $options),
             new TextField("SecondTitle", "Extra title som visas om layout 'Bluebox' är valt."),
             new WidgetImageField("LinkImageID", "Bild"),
             new TextField("ImageCaption", "Fet text som visas direkt under bild"),
             new TextAreaField("Text", "Text"),
             new TextField("LinkUrl", "Länk"),
             new WidgetImageField("ExtraLinkImageID", "Extra Bild som visas under texten."),
             new TextField("ExtraLinkUrl", "Länk om bilden under texten skall länka.")
          $this->extend('updateCMSFields', $fields);
          return $fields;
       function Title() {
          return $this->Title;

    class MyWidget_Controller extends Widget_Controller {

        * @var array
       public static $allowed_actions = array (
       public function init() {
          if (isset($this->LinkImageID) && is_numeric($this->LinkImageID)) {
             $this->LinkImageTag = DataObject::get_by_id('Image',$this->LinkImageID);
          if (isset($this->ExtraLinkImageID) && is_numeric($this->ExtraLinkImageID)) {
             $this->ExtraLinkImageTag = DataObject::get_by_id('Image',$this->ExtraLinkImageID);




    <div class="$Layout">
       <% if Layout == "Bluebox" %>
       <% else %>
       <a href="$LinkUrl" title="$Title">
          <% if ImageCaption %>
             <h3 class="center">$ImageCaption</h3>
          <% end_if %>
       <% end_if %>
       <% if Layout == "Bluebox" %>
          <a href="$LinkUrl" title="Läs mer">Läs mer >>></a>
       <% end_if %>
    <% if Layout == "ImageLink2" %>
       <a href="$ExtraLinkUrl" class="extra">
    <% end_if %>

    Thanks, in advance, for any help that could help me find the "bug"


  • haantje72
    Community Member
    69 Posts

    Re: My widget breaks silverstripe :( Link to this post

    I think the most relevant is that you edit yous css file and classes if your code is shown right.
    Position it in a separate div?
    <div id="MyWidget">your content</div>
    so in your case in the ss file <div id="Layout"> and not class="$Layout"

    css file for instance in yourtheme layout.css:

    #MyWidget {
       width: 200px;
       float: left;    
       margin: 10px 10px 10px 10px;
       text-align: left;

    Mostly bad css programming breaks up the site

  • oscarw_89
    Community Member
    4 Posts

    Re: My widget breaks silverstripe :( Link to this post

    Thanks.. but that wasn't it.

    I just found what was causing the problems.

    I had put


    at the end of my files.

    Removing that solved everything

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.