[英]Octobercms. How to prepare variable to component template?
Page code: 页面代码:
{% partial 'content/main' %}
Partial: [services] 部分:[服务]
{% component 'services' %}
Component: 零件:
public function prepareVars()
{
$this->page['servicesList'] = $this->getProperty(); // function returns 123
}
Component template: 组件模板:
{{ servicesList }} //does not display anything =(
Why is not the variable being passed? 为什么不传递变量?
Hmm seems something odd, not sure about your onRun
method in component 嗯,似乎有些奇怪,不确定组件中的onRun
方法
prepareVars
will not call automatically we need to call it manually.prepareVars
不会自动调用,我们需要手动调用。
did you add prepareVars
inside onRun
as when page life-cycle
called , onRun
is called automatically so we need to add prepareVars
there as well, so its code get executed
. 您prepareVars
在onRun
添加了prepareVars
,就像在调用page life-cycle
, onRun
被自动调用了,所以我们也需要在其中添加prepareVars
,以便其代码prepareVars
executed
。
public function onRun()
{
$this->prepareVars();
}
public function prepareVars()
{
$this->page['servicesList'] = $this->getProperty(); // function returns 123
}
if you are already doing this then please notify it in comment so we can look further. 如果您已经在执行此操作,请在评论中通知它,以便我们进一步查找。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.