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.

Template Questions /

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

access the variables from a parent out of an <% control ?


Go to End


4 Posts   4442 Views

Avatar
benni91

Community Member, 72 Posts

29 July 2011 at 7:16am

Edited: 29/07/2011 7:18am

Hey @ all,

If got a problem.

i build this page

Reference.ss

<% control Screens %>
	<div class="refimg">
		<a href="$Screen.url" rel="lightbox-$Title" title="$Description">$Screen.setWidth(430)</a>
	</div>
<% end_control %>
<div class="clear"></div>

Reference.php

<?php
class ReferencePage extends Page {
		
	static $allowed_children = 'none';
	static $default_parrent = 'referenzen';
	static $can_be_root = false;

	public static $db = array(
		'Date' => 'Date',
		'Category' => 'Text',
		'Site' => 'Text'
	);

	public static $has_one = array(
		'Client' => 'ClientObject',
		'Preview' => 'Image'
	);
	
	public static $has_many = array(
		'Screens' => 'ScreenObject'
	);

	function getCMSFields() {
		
		$fields = parent::getCMSFields();
		
		$fields->addFieldToTab('Root.Content.Main', $date = new DateField('Date', 'Release Date'), 'Content');
		$date->setConfig('showcalendar', true);
		
		$fields->addFieldToTab('Root.Content.Main', new TextField('Category','Web/Print/Hosting etc.'), 'Content');
		$fields->addFieldToTab('Root.Content.Main', new TextField('Site','Link zur Online Referenz (Website wenn online)'), 'Content');
		
		$clients = DataObject::get('ClientObject')->toDropDownMap('ID', 'Name');
		$fields->addFieldToTab('Root.Content.Main', new DropdownField('ClientID', 'Client', $clients, $this), 'Content');
		
		$fields->addFieldToTab('Root.Content.Screens', new ImageDataObjectManager($this, 'Screens', 'ScreenObject', 'Screen', array('Description' => 'Beschreibung'), 'getCMSFields_forPopup'));
		
		$fields->addFieldToTab("Root.Content.Preview", new ImageField('Preview', 'Preview Image 276px x 140px'));
		
		return $fields;
		
	}

}
class ReferencePage_Controller extends Page_Controller {

}

?>

and

ScreenObject

<?php
class ScreenObject extends DataObject {

	public static $db = array(
		'Description' => 'Text'
	);

	public static $has_one = array(
		'Screen' => 'Image',
		'ReferencePage' => 'ReferencePage'
	);

	public function getCMSFields_forPopup() {
    
    return new FieldSet(
      new TextField('Description', 'Beschreibung'),
      new ImageField('Screen', 'Screenshot')
    );
    
  }
	
}

?>

I'm trying to get the page title of my ReferencePage
(<a href="$Screen.url" rel="lightbox-$Title" title="$Description">$Screen.setWidth(430)</a>)

But i just get the image title.

if i try it like this

<% control Screens %>
	<div class="refimg">
		<a href="$Screen.url" rel="lightbox-<% control Parent %>$Title<% end_control %>" title="$Description">$Screen.setWidth(430)</a>
	</div>
<% end_control %>
<div class="clear"></div>

it also didn't work :/

any solutions?

Thanks Benni

Avatar
zenmonkey

Community Member, 545 Posts

29 July 2011 at 7:36am

You can use $Parent.Title or $Top.Title to temporally escape out of the control.
http://doc.silverstripe.org/sapphire/en/reference/built-in-page-controls#top

Avatar
benni91

Community Member, 72 Posts

29 July 2011 at 8:05am

Thx, $Top.Title works :)
$Parent.Title didn't

Avatar
geoffmcqueen

Community Member, 11 Posts

8 May 2014 at 5:55am

The syntax now is "$Up.Title" instead of $Parent. I'm sure it made sense to someone to change something that already worked and lead to confusion and re-writing of templates...