我正在尝试使用YouTube小部件,但似乎在Silverstripe 3中存在问题,并且它没有将DataObjectSet传递给模板,因此,我无法将数据传递给模板。所有值都在CMS中正确显示,它们仅在模板中未传递,因此它似乎是SS3中DataObjectSet的问题。我搜索得非常广泛,但在SS3中找不到它的弃用。
class YoutubeWidget extends Widget{
static $title = "My favorite video";
static $cmsTitle = "Your tube widget";
static $description = "This widget can embed clips from youtube.com";
static $db = array(
"Width" => "Int",
"Height" => "Int",
"URL" => "Text",
"Title" => "Text"
);
static $defaults = array(
"Width" => 283,
"Height" => 182
);
function getCMSFields(){
return new FieldList(
new NumericField("Width", "Video Width"),
new NumericField("Height", "Video Height"),
new TextField("URL", "Video URL"),
new TextField("Title","Title or a note about this video")
);
}
function GetVideoData(){
$output = new DataObjectSet();
$output->push(
new ArrayData(
array(
"Width" => $this->Width,
"Height" => $this->Height,
"URL" => $this->URL,
"Title" => $this->Title
)
)
);
return $output;
}
}
模板中没有填充任何变量。
<% control GetVideoData %>
<object width="$Width" height="$Height">
<param name="movie" value="$URL"></param>
<param name="allowFullScreen" value="true"></param>
<embed src="$URL" type="application/x-shockwave-flash" allowfullscreen="true" width="$Width" height="$Height"></embed>
</object>
<p style="text-align:center;">$Title</p>
<% end_control %>
如果我将控件包装在&lt;%if GetVideoData%&gt;它不访问控件,表示没有返回任何内容,即使我更改GetVideoData函数只是返回一个字符串,也会发生这种情况。即return "asdf";
答案 0 :(得分:2)
这是由于SS3的变化。我只需要放弃&#34;得到&#34;来自模板中的控制调用;
<% if VideoData %>
<% control VideoData %>
<% end_control %>
<% end_if %>
答案 1 :(得分:2)
SS3现在将使用<% loop VideoData %>
或<% with VideoData %>
代替<% control VideoData %>
。