Skip to content

Commit 78dbbad

Browse files
committed
use page renderer instead of output variable
1 parent 0200b09 commit 78dbbad

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

block_townsquare.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use block_townsquare\contentcontroller;
18-
1917
/**
20-
* Plugin strings are defined here.
18+
* Townsquare block class.
2119
*
2220
* @package block_townsquare
2321
* @copyright 2023 Tamaro Walter
@@ -41,22 +39,14 @@ public function init(): void {
4139
* @throws \core\exception\moodle_exception
4240
*/
4341
public function get_content(): stdClass {
44-
global $OUTPUT, $DB, $USER, $CFG;
42+
global $DB, $USER;
4543

4644
if ($this->content !== null) {
4745
return $this->content;
4846
}
4947

50-
$controller = new contentcontroller();
51-
$mustachedata = new stdClass();
52-
$mustachedata->content = $controller->get_content();
53-
$mustachedata->courses = $controller->courses;
54-
$mustachedata->savehelpicon = ['text' => get_string('savehelpicontext', 'block_townsquare')];
55-
$mustachedata->resethelpicon = ['text' => get_string('resethelpicontext', 'block_townsquare')];
56-
// Learnweb-Todo: If versions <M.5.0 are not supported anymore, delete this check and the old sidepanel template.
57-
$mustachedata->newsidepanel = $CFG->branch >= 500;
5848
$this->content = new stdClass();
59-
$this->content->text = $OUTPUT->render_from_template('block_townsquare/blockcontent', $mustachedata);
49+
$this->content->text = $this->page->get_renderer('block_townsquare')->render_main();
6050

6151
// Get the user settings if available.
6252
$usersettings = $DB->get_record('block_townsquare_preferences', ['userid' => $USER->id]);

classes/output/renderer.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
namespace block_townsquare\output;
2525

26+
use block_townsquare\contentcontroller;
2627
use core\exception\moodle_exception;
2728
use plugin_renderer_base;
2829

@@ -37,11 +38,19 @@ class renderer extends plugin_renderer_base {
3738
/**
3839
* Return the main content for the block townsquare.
3940
*
40-
* @param array $data Data to render the townsquare templates
4141
* @return string HTML string
4242
* @throws moodle_exception
4343
*/
44-
public function render_main(array $data): string {
45-
return $this->render_from_template('block_townsquare/blockcontent', $data);
44+
public function render_main(): string {
45+
global $CFG;
46+
$controller = new contentcontroller();
47+
$mustachedata = (object) [
48+
'content' => $controller->get_content(),
49+
'courses' => $controller->courses,
50+
'savehelpicon' => ['text' => get_string('savehelpicontext', 'block_townsquare')],
51+
'resethelpicon' => ['text' => get_string('resethelpicontext', 'block_townsquare')],
52+
'newsidepanel' => $CFG->branch >= 500,
53+
];
54+
return $this->render_from_template('block_townsquare/blockcontent', $mustachedata);
4655
}
4756
}

0 commit comments

Comments
 (0)