General developer forum

Can Blocks be used in Activity?

 
Picture of Stefan Beyer
Can Blocks be used in Activity?
 

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: -
Picture of Dave Emsley
Re: Can Blocks be used in Activity?
Particularly helpful Moodlers

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



 
Average of ratings: -
Picture of Stefan Beyer
Re: Can Blocks be used in Activity?
 

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

 
Average of ratings: -