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.

All other Modules /

Discuss all other Modules here.

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

Subsites and DataObject error


Go to End


1109 Views

Avatar
ROlckers

Community Member, 8 Posts

6 July 2012 at 4:45pm

I have a page type (ModelDetailPage) which has a data object (ModelDetailPageGallery) associated via the data object manager. I'm also using the subsites module.

I have a couple of subsites (e.g. testsite.testdomain.com, testsite2.testdomain.com) and a Main Site subsite (e.g. www.testdomain.com). I have a couple of subsite virtual page links in the subsites linking to pages in the Main Site subsite. This is purely to link up similar content across all subsites. So the Main Site has a page called Model which is of ModelDetailPage page type. This page has a couple of ModelDetailPageGallery items associated with it.

Now for the error. When I view the subsite page (www.testdomain.com) I get an error if I use an <% IF %> statement around the <% control ModelDetailPageGallery %> statement inside the template. It does work if I don't call it through the subsite virtual page links and call it as an actual page on the subsite. It does actually work if I don't use the <% IF %> and just use the <% control %>, but I'd really like to use the <% IF %> if possible.

The page:

<?php
class ModelDetailPage extends Page {
	
	public static $db = array(
	);
	
	public static $has_many = array(
		'ModelDetailPageGallery' => 'ModelDetailPageGallery'
	);
	
	public function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->removeByName("To-do");
		$fields->removeByName("Access");
		$galleryDOM = new DataObjectManager(
			$this,
			'ModelDetailPageGallery',
			'ModelDetailPageGallery',
			array('Description'=>'Description', 'RRPrice' => 'RR Price', 'getImageURL'=>'Image'),
			'getCMSFields_forPopup'
		);
		$galleryDOM->setAddTitle('a Line-up Item');
		
		$fields->addFieldToTab("Root.Content.LineUp", $galleryDOM);
		
		return $fields;
	}
	
}
class ModelDetailPage_Controller extends Page_Controller {
	
}

The dataObject:

<?php

class ModelDetailPageGallery extends DataObject {
	
	static $db = array (
		'Description' => 'HTMLVarchar(512)',
		'RRPrice' => 'Varchar(50)',
		'DownloadLink' => 'Varchar(1024)'
	);
	
	static $has_one = array (
		'ModelDetailPage' => 'ModelDetailPage',
		'Image' => 'Image'
		
	);
	
	public function getCMSFields_forPopup()	{
		return new FieldSet(
			new FileIFrameField("Image", "Image"),
			new TextField("Description", "Description (HTML allowed)"),
			new TextField("RRPrice", "RR Price"),
			new TextField("DownloadLink", "Download Link")
		);
	}
	
	public function getImageURL() {
		return '<img src="'.$this->Image()->Filename.'" width="80px" />';
	}
	
}

SortableDataObject::add_sortable_class('ModelDetailPageGallery');

The template:
(this works)

				<% control ModelDetailPageGallery %>
				<div class="grid_3">
					<a href="#" class="<% if First %>first_rc<% end_if %>">
						<img src="<% control Image.SetWidth(150) %>$Link<% end_control %>" alt="$Description" />
						<h4>$Description</h4>
						<p class="txt_link"><span class="price_car">$RRPrice</span> RRP</p>
						<% if DownloadLink %>
						<span class="txt_link"><span class="arrow_link">&raquo; </span>Download brochure</span>
						<% end_if %>
						</a>
				</div>
				<% end_control %>

(this doesn't)

				<% if ModelDetailPageGallery %>
				<% control ModelDetailPageGallery %>
				<div class="grid_3">
					<a href="#" class="<% if First %>first_rc<% end_if %>">
						<img src="<% control Image.SetWidth(150) %>$Link<% end_control %>" alt="$Description" />
						<h4>$Description</h4>
						<p class="txt_link"><span class="price_car">$RRPrice</span> RRP</p>
						<% if DownloadLink %>
						<span class="txt_link"><span class="arrow_link">&raquo; </span>Download brochure</span>
						<% end_if %>
						</a>
				</div>
				<% end_control %>
				<% end_if %>

Any help or a steer in the right direction would be much appreciated!