Hi all,
I've looked and can't find this so I suspect not but I'm developing a block and want quite a specific page layout. Is there a way to include a page layout template within the block?
Cheers
Dave
Not sure quite what you want but if it's just the block content layout wouldn't a suitable Mustache template fit the bill?
Cheers
Richard
I'm not overly keen on moustache templates but if that's a solution OK - However I'm unsure where it would go.
Cheers
Dave
Hi Dave
Again I'm not sure it will solve whatever you want to do but the basic process would be:
1. Call a renderer from your get_content() function in block_name.php, eg
$renderer = $this->page->get_renderer('block_name');
$this->content->text = $renderer->fetch_block_content();
2. Create a renderer.php file with the function fetch_block_content()
class block_name_renderer extends plugin_renderer_base {
public function fetch_block_content() {
global $USER;
$data = new stdClass();
$data->welcome = get_string('welcomeuser', 'block_name', $USER);
return $this->render_from_template('block_name/block_content',
$data);
}
}
3. Create Mustache template to display the content (block_content.mustache in your templates folder)
<div>
<h3>{{welcome}}</h3>
</div>
(see example Moodle code for the expected comments and so on).
You can use Bootstrap 4 classes in that template to style your layout. Of course you can add or pass more data items to your renderer function to build up $data and pass things to the template (url's for example). More example code can be found here:
https://github.com/richardjonesnz/moodle-block_superframe
Honestly once you get past the initial horror of dealing with a whole three files at once it does get easier . The big thing for me is that the block layout can visualised cleanly in HTML.
Richard