[英]How do you render a component within a partial in OctoberCMS?
In OctoberCMS, I am creating a component.在 OctoberCMS 中,我正在创建一个组件。 In the component's
default.htm
partial file ( /acme/myplugin/components/mycomponent/default.htm
) I can include any other registered component by doing:在组件的
default.htm
部分文件( /acme/myplugin/components/mycomponent/default.htm
)中,我可以通过以下方式包含任何其他已注册的组件:
{% component 'someComponentName' %}
However if I have the following code to handle an AJAX request:但是,如果我有以下代码来处理 AJAX 请求:
public function onAjaxRequest()
{
return [
'#ajaxUpdate' => $this->renderPartial('@dates-partial'),
];
}
and in my dates-partial.htm
file I put the same contents as in my default.htm
file, the someComponentName
component is not rendered.在我的
dates-partial.htm
文件中,我放置了与我的default.htm
文件中相同的内容, someComponentName
组件未呈现。 I also tried putting the following at the top of the file:我还尝试将以下内容放在文件顶部:
[someComponentName]
==
however this is outputted directly as text to the page.但是,这会直接作为文本输出到页面。
How can I have renderPartial()
render a partial containing a component?如何让
renderPartial()
渲染包含组件的部分?
Hi I tried your approach but seems its working for me.嗨,我尝试了您的方法,但似乎对我有用。 let me share howI did the things.
让我分享一下我是怎么做的。
My Page
我的页面
title = "compo-in-partial-in-ajax"
url = "/compo-partial-ajax"
layout = "default"
is_hidden = 0
[newCompo]
[newOne]
==
<!-- AJAX enabled form -->
<form data-request="onTest">
<!-- Action button -->
<button type="submit">Call Ajax</button>
</form>
<div id="ajaxUpdate">
Default content.
</div>
{% component 'newCompo' %}
I have added 2 component
我添加了 2 个组件
newCompo
<- which is used to render content on page. newCompo
<- 用于在页面上呈现内容。 basically in its 'default.htm' I added {% component 'newOne' %}
so I am rendering another component inside.{% component 'newOne' %}
所以我在里面渲染另一个组件。newOne
<- this is component which we are going to render inside our partial. newOne
<- 这是我们要在局部渲染的组件。this is my ajax handler
这是我的 ajax 处理程序
public function onTest() {
return ['#ajaxUpdate' => $this->renderPartial('@partial.htm')];
}
newCompo
component's ->default.htm
newCompo
组件的 ->default.htm
{% component 'newOne' %}
newOne
component's ->default.htm
newOne
组件的 ->default.htm
<h1>Newone</h1>
Partial file which is inside
components/newcompo
->partial.htm
位于
components/newcompo
->partial.htm
中的部分文件
<h4>partial</h4>
{% component 'newOne' %}
Normal
普通的
After ajax Call
ajax 调用后
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.