crating a new block - using the example simpleHTML - need help

crating a new block - using the example simpleHTML - need help

by Raphael Goldman -
Number of replies: 2

Hi,

I created the block, then I created the edit_form file,

where do I need to put those code lines:

if (! empty($this->config->text)) {
$this->content->text = $this->config->text;
}

link to the tutorial

http://docs.moodle.org/dev/Blocks

Thanks

Average of ratings: -
In reply to Raphael Goldman

Re: crating a new block - using the example simpleHTML - need help

by Ray Morris -

You would put it at the beginning of the get_content() function as per the tutorial.

In reply to Ray Morris

Re: crating a new block - using the example simpleHTML - need help

by roc mehra -

Does not need to put this lines.

Here is the code which i have do recently is

<?php
require_once("{$CFG->libdir}/formslib.php");
    
    class block_simplehtml extends block_base {
        public function init() {
            $this->title = get_string('simplehtml', 'block_simplehtml');
            
            }
            public function get_content() {
                if ($this->content !== null) {
                return $this->content;
                }
             global $COURSE,$DB;
            $this->content         =  new stdClass;
            $this->content->text   = 'The content of our SimpleHTML block!';
            
        
            // The other code.
 
            $url = new moodle_url('/blocks/simplehtml/view.php', array('blockid' => $this->instance->id, 'courseid' => $COURSE->id));
            $this->content->footer = html_writer::link($url, get_string('addpage', 'block_simplehtml'));
            
            
            if ($simplehtmlpages = $DB->get_records('block_simplehtml', array('blockid' => $this->instance->id))) {
                $this->content->text .= html_writer::start_tag('ul');
            foreach ($simplehtmlpages as $simplehtmlpage) {
        $pageurl = new moodle_url('/blocks/simplehtml/view.php', array('blockid' => $this->instance->id, 'courseid' => $COURSE->id, 'id' => $simplehtmlpage->id, 'viewpage' => '1'));
        $this->content->text .= html_writer::start_tag('li');
        $this->content->text .= html_writer::link($pageurl, $simplehtmlpage->pagetitle);
        $this->content->text .= html_writer::end_tag('li');
        }
    $this->content->text .= html_writer::end_tag('ul');
    }
            return $this->content;
        }
   // Here's the closing bracket for the class definition

}
    // The PHP tag and the curly bracket for the class definition
    // will only be closed after there is another function added in the next section.



?>