Can Blocks be used in Activity?

Can Blocks be used in Activity?

بواسطة - Stefan Beyer
عدد الردود: 2

I'm writing an activity module in witch the admin wants to add some content aside, like text blocks.

Can the moodle block system somehow be used in the rendering process of an activity?

متوسط التقييمات: -
رداً على Stefan Beyer

Re: Can Blocks be used in Activity?

بواسطة - Dave Emsley

You can do this.

If you add to your block_MYBLOCK.php file something like:

    public function get_content() {
        global $CFG, $OUTPUT, $USER;
        if ($this->content !== null) {
            return $this->content;
        }

        // we only want to show this block on certain pages.
        $showOn = ['mod-quiz-attempt', 'mod-quiz-summary'];
        if (array_search($this->page->pagetype, $showOn) === false) {
            echo "<!-- We're not showing on this page -->";
        }
//
//       Rest of your code to generate content
//
return $this->content;
}


This block will only be visible on pages of type mod-quiz-attempt, and mod-quiz-summary

Hope this makes sense.

Dave