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.

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

[solved] variable in content return


Go to End
Reply


1092 Views

Avatar
lerni

Community Member, 81 Posts

31 March 2010 at 2:52am

Edited: 01/04/2010 7:41am

hi there

i've made a simple gallery and now i wanna be able to insert it per variable in the content field. like in this recipe:

http://doc.silverstripe.org/doku.php?id=recipes:customising-content-in-your-templates&s=paypal

return a string for a variable works but returning the galleryitems just prints "ComponentSet".

update:
it works now. with the foreach loop i can access the items.

class GalleryPage extends Page {
	static $db = array(
	);
	static $has_one = array(
	);
	static $has_many = array(
		'GalleryItems' => 'GalleryItem'
	);
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$manager = new ComplexTableField(
			$this,
			'GalleryItems',
			'GalleryItem',
			array(
				'Thumbnail' => 'Thumbnail',
				'Beschreibung' => 'Beschreibung',
				),
			'getCMSFields_forPopup',
			'PageID = '.$this->ID
		);
		$fields->addFieldToTab("Root.Content.Galerie",$manager);
		
		return $fields;
	}

	static $defaults = array(
		'Content' => '$GalleryPage'
	);
}
class GalleryPage_Controller extends Page_Controller {
	public function init() {
		parent::init();
		Requirements::block('jsparty/prototype.js');
	}


	function Content() {
		$content = str_replace('$Visiogallery', $this->BB(), $this->Content); 
		return $content;
	}
	function BB() {
		$output = "";
		$output = '<ul class="gallery">';
		$items = DataObject::get("GalleryItem");
		foreach ($items as $item) {
			$output .= '<a rel="b_group" href="' . $item->Bild()->Big()->URL . '" title="' . $item->Beschreibung . '"><img alt="' . $item->Beschreibung . '" src="' . $item->Bild()->Small()->URL . '" /></a>';
			$output .= '<p>' . $item->Beschreibung . '</p>';
		}
		$output .= '</ul>';
		return $output;
	}
}