null

When you pass it in like that, your template variables should be loaded in the top-level. You'd expect to see a dump into your template

null

Try putting $Me.Debug into the template to see if it's getting passed in

taoceanz

The array passed contains not values containing the work 'data' either

taoceanz

@null, I've just changed the variable and template name in this. Nothing contains the word data except for $arrayData

null

https://github.com/silverstripe/silverstripe-framework/issues/8088

Show 1 attachment(s)
phptek

Affected Version

framework 4.1.0 / PHP7.0

Description

Creatiing a simple DataObject with a single Text field and naming it "Data" will cause problems when Calling $this->obj('Data') in any context. In my case, I am using the restfulserver package which attempts to decompose a DataObject into JSON via JSONDataFormatter which makes use of ViewableData::obj() when casting.

This occurs becuase of the core method DataObject::data() which is "blindly" called by ViewableData::obj() instead of the desired DBField by SilverStripe\Core\CustomMethods::hasMethod().

The problem can be demo'd fairly succinclty below:

Steps to Reproduce

class Page extends SiteTree
{
    private static $db = [
         'Data' => 'Text''
    ];

    public function getCMSFields()
    {
        var_dump($this->obj('Data')); // prints `SiteTree` not `DBText`
        die;
    }

Workaround

The workaround is to declare a method on your datamodel named for the field and call getField('Data') from it, thus inverting otherwise default control.

Suggestions

"Data" is used in a DataObject context as DataObject::data() and is therefore a reserved word. As such, userland logic could receive an Exception on dev/build when attempting to declare a field-name that is reserved. The reserved field-names could be declared as an immutible array in DataObject to permit further fields to be added by core-devs in a flexible manner going forward.

Related PRs

https://github.com/silverstripe/silverstripe-framework/pull/8731|#8731

Hide attachment content
null

^^ there was a framework bug raised recently where you can't use the word "Data" as a field name

taoceanz

This is what's in place to pass data to the template: (edit: changed data to myData. Note variable and template names not actual names used in effected code)

  1. $arrayData = new ArrayData(array(
  2. 'myData' => $myData,
  3. ));
  4. $html = $arrayData->renderWith('template');
stephenmcm

It needs to be an ArrayList/ArrayData raw arrays don't work well in templates

taoceanz

Hey team, I'm struggling to get information displaying after passing it via renderWith to a Template file. The variable (a multi-dimensional array) passed to the template is accessible but I can't seem to get anything inside it.

dorsetdigital

https://www.silverstripe.org/blog/2019-community-survey-have-your-say/

Show 1 attachment(s)
silverstripe.org  
2019 Community Survey—Have your say

It’s time to have your say again! We’re running our (slightly delayed) annual community survey. This is your chance to tell us about you, how you’re using SilverStripe, and if we’re going in the right direction.

Hide attachment content
Patrick Nelson

I'm not sure if I see the logo, a galaxy, or a blue snake. either way, you don't wanna step on it.