silverstripe/sapphire — pull request #186 by AngryPHPNerd (2012-02-09 19:11:11+00:00)
Title: Customised Object will call forTemplate() of ArrayData object.

If you have something like this:

```php
public function getSubObject()
{
$o = parent::getSubObject();

if ($this->EnableFoo) {
$o->customise(array(
'foobar' => 'baz',
));
}

return $o;
}

public function my_action()
{
return $this->customised(array(
'Blar' => $this->getSubObject()
));
}
```

and in template:

```

{$Blar}
```

you will get

```

array(
'foobar' => 'baz'
)
```
witch is not what I expect ... the point is that the forTemplate() method of the customised (ArrayData) object is called.

I don't know if my whay to check against ArrayData instances is the correct way to fix this issue.

Maybe is it would be better to make following:

```
protected $_useCustomisedForTemplate = false;

public function setUseCustomisedForTemplate($bool) {
$this->_useCustomisedForTemplate = $bool;
}

public function forTemplate() {
return $this->_useCustomisedForTemplate ? $this->customised->forTemplate() : $this->original->forTemplate();
}
```

```
$o = $o->customise(array(...));
$o->setUseCustomisedForTemplate(true);
return $o;
```