Jump to:

794 Posts in 408 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » Widget placement control

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 1264 Views
  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Widget placement control Link to this post

    Hello,
    I have an issue with widgets - how are they organised?
    I have been able to add widgets to my front page, cause i wanna be able to pull some content dinamicaly from news(converted blog) sections, random content from enciclopedia section , latestest blog post titles and so on, but I wanna be able to control where will each of those things be posted on my homepage (don't rly want them in a sidebar and only in the sidebar).
    As far as i see, adding $sidebar will just place them all in the same place w/o any placement control (except margins, but they will be one under another in every case)
    I even tried using it as array and doing $sidebar(1), &sidebar(2)... etc, but as it seems, it doesn't work that way (just lists them all in every place i typed $sidebar).
    I am starting to look inside the code now, but don't know where exactly to look, so i will try and find it on my own, but if som1 had similar issues and manage to find a solution, I would be very grateful!

    Thank you all in advance!

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Widget placement control Link to this post

    Ok, so I am trying it like this (and plz correct me if i'm wrong cause i do have some errors):
    instear making 1 Widgetarea I am trying to cr8 several (in this first try I am making 5 different areas):

    <?php
    class Page extends SiteTree {
       
       public static $db = array(
       );

       public static $has_one = array(
          "kronika" => "WidgetArea",
          "encik" => "WidgetArea",
          "izdvojeno" => "WidgetArea",
          "novosti" => "WidgetArea",
          "za_korisnike" => "WidgetArea"
          
       );
       
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Widgets",
       new WidgetAreaEditor("kronika","encik","izdvojeno","novosti","za_korisnike"));
    return $fields;
    }
    }

    .
    .
    .
    .
    ../dev/build works fine, but then as I am trying to access ../admin this error pops out:
    .
    .
    .
    .

    [Warning] Invalid argument supplied for foreach()
    GET /ss/admin

    Line 33 in /var/www/ss/cms/code/WidgetAreaEditor.php

    Source

    24       Requirements::javascript(CMS_DIR . '/javascript/WidgetAreaEditor.js');
    25
    26       return $this->renderWith("WidgetAreaEditor");
    27    }
    28    
    29    function AvailableWidgets() {
    30       
    31       $widgets= new DataObjectSet();
    32       
    33       foreach($this->widgetClasses as $widgetClass) { <---- this is in red
    34          $classes = ClassInfo::subclassesFor($widgetClass);
    35          array_shift($classes);
    36          foreach($classes as $class) {
    37             $widgets->push(singleton($class));
    38          }
    39    

    Could som1 try and figure out what i'm doing wrong and how it should be done?

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Widget placement control Link to this post

    Hello, the Third!

    So, this seems more and more like a monologue, but mby it'll help som1 one day

    it was solved about some time ago by placing :

    class Page extends SiteTree {
       
       public static $db = array(
       );

       public static $has_one = array(
          "kronika" => "WidgetArea",
          "encik" => "WidgetArea",
          "izdvojeno" => "WidgetArea",
          "novosti" => "WidgetArea",
          "za_korisnike" => "WidgetArea"
          
       );
       
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("kronika"));
    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("encik"));
    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("izdvojeno"));
    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("novosti"));
    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("za_korisnike"));
    return $fields;
    }
    }

    in Page.php (it also works in HomePage.ss, ofc, if you only wish to add it to HomePage)
    the thing i'm wondering now is if this is rly the most elegant solution that it can be done? Any ideas?

    Also, i am looking now, but if som1 can explain the difference between has_one, has_many and many_many and what are they intended to be used like?

    Thank you all in advance!

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