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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Control Widgets


Go to End


4 Posts   2434 Views

Avatar
borriej

Community Member, 267 Posts

29 April 2011 at 3:51am

Edited: 30/04/2011 6:22am

Hello

I have a blog with blog entry's
some blog entry's contain widgets, one of the widgets is featuredvideo
ok now i have a page media..

this media page collects all the media items like video's/pictures/audio from the blog entry's

So first im doing this:

class Media_Controller extends Page_Controller {
	function ViewAll($num=9999) {
		$news = DataObject::get_one("BlogHolder");
		return ($news) ? DataObject::get("BlogEntry", "ParentID = $news->ID", "Date DESC", "", $num) : false;
	}

in the template i do this:

                        <% if inSection(video) %>
                        
                            <div class="clearfix pbot40">
                                <h2>Video's</h2>
                                <br>
                                <% control ViewAll %>
                                    <% if Widgets %>
                                                <div class="MediaVideoController">
                                                   $Widgets
                                                </div>
                                    <% end_if %>
                                <% end_control %>
                             </div>
                       
                        <% end_if %>

A) I would like to filter on featured video.. so.. if widgets.. if featured video... echo featured video.. now i get alot of empty div's printed in the source code.
B) When you use featured video you get a div wrapper which contains your video's. So i when i have 3 video's in one article i get them along side eachother.. but (see example) i want all the video's in its own wrapper and nicely floating along side eachother. I would like to bypass the Widget template and just control the videos from the media template. But i dont know how to control widgets..

Any idea's?

Avatar
Zauberfisch

Community Member, 30 Posts

29 April 2011 at 10:16am

I never used Widgets before, but by looking into the code it seems Widget is extending DO, so it is rather simple getting all video widgets:

function getAllVideoWidgets() {
return DataObject::get('FeaturedvideoWidget');
}

<% control getAllVideoWidgets %>
<div class="Featuredvideo">
$Content or $WidgetHolder or $forTemplate or something, you need to try around a bit, but I think something like that should work
</div>
<% end_control %>

Avatar
Plato Creative

Community Member, 26 Posts

29 April 2011 at 10:38am

Edited: 29/04/2011 10:44am

(3:02:40 AM) borriej [~52aa1a47@littleted.silverstripe.com] entered the room.
(3:03:07 AM) borriej: hw;;p
(3:03:11 AM) borriej: hello
(3:03:25 AM) borriej: im using a function to get all the blog entry
(3:03:26 AM) borriej: s
(3:03:42 AM) borriej: function ViewAll($num=9999) { $news = DataObject::get_one("BlogHolder"); return ($news) ? DataObject::get("BlogEntry", "ParentID = $news->ID", "Date DESC", "", $num) : false; }
(3:04:13 AM) borriej: i want all the blog entry's with featured video displaye
(3:04:18 AM) borriej: displayed
(3:04:25 AM) borriej: so i just did $Wdigets
(3:04:40 AM) borriej: but all blog entry's with any widgets are now being displayed
(3:05:01 AM) borriej: but i want only the featured video widget
(3:05:05 AM) borriej: how do i filter this?
(3:05:10 AM) borriej: tried many things, but did not work
(3:07:59 AM) borriej: any one?
(3:08:44 AM) borriej: i need something <% control widgets %><% if Title==Video %>$Widgets <% end_control %><% end_control %>
(3:08:49 AM) borriej: but this doesent work
(3:14:23 AM) borriej: Dudes
(3:14:26 AM) borriej: please help me

Hi borriej,

I had typed out a bigger more thorough post, but I lost it somehow and Zauberfisch seems to have covered much of what I said far more succinctly. So I'll just add this:

I think the biggest problem you're finding is caused by not controlling deep enough in your templates. Anything that comes out through a template should be able to be controlled into. In the above code you put on IRC you controlled into widgets, but then called it again when already inside (resulting in no such variable, thus it didn't work). You wanted to control some specific element of the video widget to get what you wanted.

Look at your data object (video widget) and see how it's structured. This will help you understand what you can call from in the templates. You'll want to call the $VideoCode (as an example) to get just the code, and you can form your own html containers around it. This will bypass the widget template that's causing your videos to not align nicely 3 wide on the example media page. Other info to help you out can come from inspecting how your widget is included in your page (how to control into it from a page to customise the html there), and how the table in the database is also structured (can help with filtering when you DO::get() )

In the case that the full HTML (including containing div) is stored in the database (unlikely), you'll have to write a custom getter that fetches the info then strips the containing div before putting the code out. This way you can float everything next to each other.

Avatar
borriej

Community Member, 267 Posts

30 April 2011 at 6:22am

ok thx for your replies im a bit further now..

Wel next step. I want a title field to added to the featured video

so i tried this:

<?php

// Featured Video Widget 0.1 for the SilverStripe Blog Module
// 10.11.2007
// By abimanyuraja@gmail.com
// Save the entire widget folder to the root folder and run "db/build".

class FeaturedvideoWidget extends Widget {
	static $db = array(
		//start my add
		"VideoName" => "Text",
		// end my add
		
		"VideoProvider" => "Varchar",
		"Url" => "Text",
		"YouTubeCode" => "Text"
	);
	function getMyParent(){ 
		return dataObject::get_by_id('BlogEntry', $this->BlogEntryID); 
	}
	//public static $youtubeTitle; 
	static $title = "Video";
	static $cmsTitle = "Featured Video";
	static $description = "Display one video from Youtube, Google Video or Vimeo. Full sized videos can also be viewed";
	
	//start my add
	public static $VideoName;
	// end my add	

	public function getTitle() { 
		if (!$this->youtubeTitle) { 
		  $url = "http://gdata.youtube.com/feeds/api/videos/". $this->YouTubeCode; 
		  $doc = new DOMDocument; 
		  $this->youtubeTitle = (@$doc->load($url))?$doc->getElementsByTagName("title")->item(0)->nodeValue:''; 
		} 
		return $this->youtubeTitle; 
	} 		
		
	function GetFeaturedVideo() {
	 try {
				
		Requirements::javascript("widgets_featuredvideo/js/swfobject.js");
		Requirements::javascript("jsparty/prototype15.js");
		Requirements::javascript("widgets_featuredvideo/js/effects.js");
		Requirements::javascript("widgets_featuredvideo/js/lightwindow.js");
		
		$parsedUrl = parse_url($this->Url);
		
		//start my add
		$VideoName = $this->VideoName;
		// end my add	
	
		switch ($this->VideoProvider) {
		case "youtube":
			parse_str($parsedUrl['query'], $id);
			$videoUrl =  "http://youtube.com/v/" . $id['v'];
			$videoID =  $id['v'];
			$width = 170;
			$height = 80;
			break;
		case "googleVideo":
			parse_str($parsedUrl['query'], $id);
			$videoUrl =  "http://video.google.com/googleplayer.swf?docid=" . $id['docid'];
			$width = 410;
			$height = 336;
			break;
		case "vimeo":
			$id = split("/", $parsedUrl['path']);
			$videoUrl =  "http://www.vimeo.com/moogaloop.swf?clip_id=" . $id[1] . "&amp;server=www.vimeo.com&amp;fullscreen=1";
			$width = 480;
			$height = 360;
			break;
		default:
			$VideoName = "";
			$videoUrl = "";
		}
				
		$output = new DataObjectSet();

		$output->push(new ArrayData(array(
					//start my add
					"VideoName" =>  $VideoName,
					// end my add	
					"Url" =>  $videoUrl,
					"Width" => $width,
					"Height" => $height,
					"YouTubeCode" => $videoID,
		)));
		
		return $output;
			
		} catch(Exception $e) {
			return false;
		}
		
	}

	function getCMSFields() {
		return new FieldSet(
							
			//start my add
			new TextField("VideoName", "Video Title"),
			// end my add	
			
			new TextField("Url", "Video URL"),
			new OptionsetField(
					$name = "VideoProvider",
					$title = "Video Site",
					$source = array(
						"youtube" => "Youtube",
						"googleVideo" => "Google Video",
						"vimeo" => "Vimeo" 
						),
					$value = "youtube"
				)		
		);
	}
}
class FeaturedvideoWidget_Controller extends Widget_Controller {


}
?>

But when i fill in the featured video fields (title & link) and hit save.. the fields are empty after the green checkmark..

When Zauberfisch is in the admin.. he can save it.

So what is going on?

I dont understand, did flush and dev/build many times..

Is my hosting nagging me?