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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

What variable for page control?

Go to End

6 Posts   2105 Views


74 Posts

10 December 2008 at 5:17pm

I'm trying to use the Page control to bring in the youtube videos from a youtube gallery page. But I can't figure out what variable I need to get the "content"(videos) of the page. I've tried everything that made sense to me & some things that didn't.

Here's the code

	<% control Page(videos) %>
	<% end_control %>

I'm just confused on why I can't seem to get this to work. Any help would be super. Thanks.


74 Posts

12 December 2008 at 3:49pm

Nobody knows how to do this? I'm getting desperate here. Any ideas are welcome. Thanks.


Forum Moderator, 5523 Posts

12 December 2008 at 4:35pm

Have you looked at the YoutubeVideoPage.php file or the code file in the Youtube folder? I have no idea off the top my head what you need to include but it would be in there.

EDIT: I think you need to do <% control YoutubeVideos %> - this function YoutubeVideos() is the one that returns all the video objects.. Not sure where the info is stored tho.


74 Posts

12 December 2008 at 5:02pm

I'm not sure if maybe we're looking in 2 different modules or what. I have a youtubeservice folder & in the code folder I have YoutubeGallery.php, YoutubeService.php, YoutubeWidget.php.

I've looked at all of them & YoutubeGallery.php is the one it's using. I've tried all the variables in there & get nothing. So I'm stumped.

I tried <% control YoutubeVideos %> but still can't get it to work. Here's the code from YoutubeGallery.php.

class YoutubeGallery extends Page {
   // define your database fields here - for example we have author
   static $db = array(
   		"Method" => "Int",
		"User" => "Varchar",
		"Query" => "Varchar",
		"CategoryTag" => "Varchar",
		"Playlist" => "Varchar",
		"PerPage" => "Int",
		"Sortby" => "Varchar"
   static $defaults = array(
		"Method" => 1,
		"PerPage" => 10,
		"Sortby" => 'relevance'
  static $icon = "youtubeservice/images/youtube";
   // add custom fields for this youtube gallery page
   function getCMSFields($cms) {
   	  Requirements::javascript( 'youtubeservice/javascript/YoutubeGallery_CMS.js' );
      $fields = parent::getCMSFields($cms);
      $fields->addFieldToTab("Root.Content.Videos", new DropdownField("Method", "Select ", array(
				'1' => 'Videos containing phrase',
				'2' => 'Videos by Category or Tag',
				'3' => 'Videos uploaded by',
				'4' => 'Favorite videos of',
				'5' => 'Videos from playlist')));
      $fields->addFieldToTab("Root.Content.Videos", new TextField("User","Youtube Username"));
      $fields->addFieldToTab("Root.Content.Videos", new TextField("Query","Search for"));
      $fields->addFieldToTab("Root.Content.Videos", new TextField("CategoryTag", "Category or Tag"));
      $fields->addFieldToTab("Root.Content.Videos", new TextField("Playlist", "Playlist ID"));      
      $fields->addFieldToTab("Root.Content.Videos", new NumericField("MaxResults", "Per Page", 10));
      $fields->addFieldToTab("Root.Content.Videos", new DropdownField("Sortby", "Sort by (descending)", array(
				'relevance' => 'Relevance',
				'updated' => 'Most Recent',
				'viewCount' => 'Most Viewed',
				'rating' => 'Most Rated')));
      return $fields;
   function YoutubeVideos(){
		$youtube = new YoutubeService();
		$page = isset($_GET['page'])? $_GET['page']: 1;
		$start_index = (($page-1) * $this->PerPage) + 1 ;
		switch ($this->Method){
			case 1:
				$videos = $youtube->getVideosByQuery($this->Query, $this->PerPage, $start_index, $this->Sortby);
			case 2:
				$videos = $youtube->getVideosByCategoryTag($this->CategoryTag, $this->PerPage, $start_index, $this->Sortby);
			case 3:
				$videos = $youtube->getVideosUploadedByUser($this->User, $this->PerPage, $start_index, $this->Sortby);
			case 4:
				$videos = $youtube->getFavoriteVideosByUser($this->User, $this->PerPage, $start_index, $this->Sortby);
			case 5:
				$videos = $youtube->getPlaylist($this->Playlist, $this->PerPage, $start_index, $this->Sortby);
		$outputHTML = "<div class='mainVideoContainer'><ul class='youtubevideos'>";
		foreach($videos as $video){	
			$duration = round((float)$video->content_duration/60, 2);	
			$video->player_url = str_replace("watch?v=","/v/",$video->player_url);
			$outputHTML .= '<div class="videoItem"><object width="425" height="344"><param name="movie" value="'.$video->player_url.'"></param><param name="allowFullScreen" value="true"></param><embed src="'.$video->player_url.'" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object><div class="info"><h6>'.$video->title.'</h6><p>'.$video->description.'<br/><strong>Duration : </strong>'.$duration.'</p></div></div>'; 	
			//$outputHTML .=  '<li><div class="still"><a href="'.$video->player_url.'" title="'.htmlentities($video->title).'"><img src="'.$video->thumbnail_url.'" alt="'.htmlentities($video->title).'"/></a></div><div class="info"><h6><a href="'.$video->player_url.'" title="'.htmlentities($video->title).'">'.$video->title.'</a></h6><p>'.$video->description.'<br/><strong>Duration : </strong>'.$duration.'</p></div></li>';
		$outputHTML .= "</ul></div>";

		$outputHTML .= "<div class='pages'><div class='paginator'>";
		$outputHTML .= $youtube->getPages();
	$outputHTML .= "</div><span class='results'>(".$youtube->getTotalVideos()." Videos)</span></div>";
	else {
	$outputHTML .= "<span>Sorry!  Gallery doesn't contain any images for this page.</span>";
		return $outputHTML;

class YoutubeGallery_Controller extends Page_Controller {
	function init() {
      if(Director::fileExists(project() . "/css/YoutubeGallery.css")) {
         Requirements::css(project() . "/css/YoutubeGallery.css");
   function Content(){
			return $this->Content.$this->YoutubeVideos();




Forum Moderator, 5523 Posts

12 December 2008 at 5:14pm

Does any youtube videos exist?

If you add Debug::show($this->YoutubeVideos()); in the function init() { } does it output anything


74 Posts

12 December 2008 at 5:26pm

I think I added that in the right place but it didn't output anything.

I am getting videos though on the main Youtube Gallery page.

This is part of the issue. I've got it working on one page but I can't get any videos on a second page. Either by making the Home page a Youtube Gallery page or by trying to pull in the content of the videos page. Ultimately I just need to pull in 4-5 videos to the home page. Any ideas on a better way to do it?