在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"
}
}}
https://github.com/moodle/moodle/blob/1d99ba19a21d57e9f1ed4211a8eeee00e50b7baf/course/format/templates/local/content/section/cmlist.mustache
但這是挑戰。如何獲取具有提供模板所需資料的格式的物件,以便它可以呈現正確的 CM 串列項?
目前我正在嘗試:
$sectionData = get_fast_modinfo($course->id)->get_section_info($section);
但它似乎并沒有以正確的方式回傳結構化的資料。
任何幫助表示贊賞。
uj5u.com熱心網友回復:
您可以使用渲染類的功能export_for_template。cmlist像這樣的東西:
$cmlist = new \core_courseformat\output\local\content\section($format, $section);
$data->cmlist = $cmlist->export_for_template($OUTPUT);
然后將資料發送到模板。我建議你模仿穆德爾在這里表演的行為: https ://github.com/moodle/moodle/blob/7ce003b666a66b465ce9335f430a6e4d3535a7f1/course/format/classes/output/local/content/section.php#L223
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/531468.html
標籤:模板穆勒胡子lms
上一篇:確定可變引數模板引數是編譯時間
