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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Widgets /

Discuss SilverStripe Widgets.

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

Widget placement control


Go to End


3 Posts   2078 Views

Avatar
Mackodlak

Community Member, 95 Posts

15 April 2011 at 7:36pm

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!

Avatar
Mackodlak

Community Member, 95 Posts

15 April 2011 at 8:59pm

Edited: 15/04/2011 9:03pm

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?

Avatar
Mackodlak

Community Member, 95 Posts

16 April 2011 at 12:18am

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!