How to pass custom data to a template

和自甴很熟 提交于 2019-12-03 16:16:10

in SilverStripe 3.0 there are the 2 things called <% loop %> and <% with %>

  • <% loop %> expects anything that implements SS_List (eg: DataList, ArrayList)
  • <% with %> accepts any type of object that extends ViewAbleData I think (eg: DataObject, ArrayData, ...)

(in SilverStripe 2.x there is just <% control %> which does both things)

so, you want to do <% loop TwitterFeed %>? Then you need to return an ArrayList

a short example (not tested, but should work):

    public function getTwitterFeed() {
            return new ArrayList(array(
                    new ArrayData(array(
                            'Name' => 'Zauberfisch',
                            'Message' => 'blubb',
                    )),
                    new ArrayData(array(
                            'Name' => 'Foo',
                            'Message' => 'ohai',
                    )),
                    new ArrayData(array(
                            'Name' => 'Bar',
                            'Message' => 'yay',
                    ))
            ));
    }


    <% loop TwitterFeed %>
            $Name wrote: $Message<br />
    <% end_loop %>

so, just turn your array that you get from twitter into ArrayData objects and put them all into a ArrayList (each tweet should be 1 ArrayData Object)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!