Can Blocks be used in Activity?

Can Blocks be used in Activity?

by Stefan Beyer -
Number of replies: 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?

Average of ratings: -
In reply to Stefan Beyer

Re: Can Blocks be used in Activity?

by 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



In reply to Dave Emsley

Re: Can Blocks be used in Activity?

by Stefan Beyer -

thanks for your reply - but if I get this right, this is for writing a block - but I'm writing an activity.