【发布时间】:2023-02-17 23:40:38
【问题描述】:
在moodle(4.0)中我需要打电话
$this->output->render_from_template('core_courseformat/local/content/section/cmlist', $sectionData);
从渲染器中。目标是在页面的特定位置呈现正常的本机 cmlist 组件。但是我目前获取 $section 值的方式似乎不起作用。我的模板不呈现任何内容。我可以从 github 源代码中看到该模板需要以下格式的数据:
Example context (json):
{
"cms": [
{
"cmitem": {
"cmformat": {
"cmname": "<a class=\"aalink\" href=\"#\"><span class=\"instancename\">Forum example</span></a>",
"hasname": "true"
},
"id": 3,
"module": "forum",
"extraclasses": "newmessages"
}
},
{
"cmitem": {
"cmformat": {
"cmname": "<a class=\"aalink\" href=\"#\"><span class=\"instancename\">Assign example</span></a>",
"hasname": "true"
},
"id": 4,
"module": "assign",
"extraclasses": ""
}
}
],
"hascms": true,
"showmovehere": true,
"movingstr": "Moving this activity: folder example",
"cancelcopyurl": "#",
"movetosectionurl": "#",
"strmovefull": "Move 'folder example' to this location"
}
}}
但这就是挑战。我如何获得该格式的对象以及提供模板所需的数据,以便它可以呈现正确的 CM 列表项?
目前我正在尝试:
$sectionData = get_fast_modinfo($course->id)->get_section_info($section);
但它似乎并没有以正确的方式返回结构化的数据。
任何帮助表示赞赏。
【问题讨论】:
标签: templates moodle mustache lms