Use Mustache Template in Block Module?

Re: Use Mustache Template in Block Module?

by Ryan Carpenter -
Number of replies: 0
Ahh, I'm meant to save the result of render_from_template to $this->content_text.  I didn't catch that part before.  Thanks a lot!

/block_my_plugin.php

<?php
class block_my_plugin extends block_base {
  public function init() {
    $this->title = get_string('my_plugin', 'block_my_plugin');
  }

  public function get_content() {
    global $USER, $COURSE, $PAGE, $OUTPUT;

    $PAGE->requires->js('/blocks/my_plugin/lib/d3.v2.min.js');
    $PAGE->requires->js_call_amd(
      'block_my_plugin/my_plugin',
      'init',
      array(
        $USER,
        $COURSE
      )
    );

    $this->content->text = $OUTPUT->render_from_template('block_my_plugin/my_plugin', new stdClass());
    return $this->content;
  }
}