简体   繁体   中英

When adding a custom block moodle shows [[pluginname]]

I am creating a custom block for moodle and when I try to add it into a page is shown as follows:

情绪名称的显示方式

Instead of a specified name.

The version.php file has these:

$plugin->component = 'block_userlist';
$plugin->version = 2019050316;
$plugin->requires = 2018120300;

And the block is defines as:

defined('MOODLE_INTERNAL') || die();

class block_userlist extends block_base {
    public function init() {
        $this->title = get_string('userlist', 'block_userlist');
    }
    // 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.

    public function get_content() {
        global $DB;

        // if ($this->content !== null) {
        //   return $this->content;
        // }

        $user = $DB->get_record_sql('SELECT COUNT(*) as total_users FROM {user};');

        $this->content         =  new stdClass;
        $this->content->text  .= 'The content of our ';
        $this->content->text  .= html_writer::tag('span','UserList',['style'=>'color:red']);
        $this->content->text  .= ' block!';
        $this->content->footer = "Τotal Users: $user->total_users";
        return $this->content;
    }
}

So how can I set a name different from [[pluginame]] ?

You need to add a file within your plugin called lang/en/block_NAMEOFYOURPLUGIN.php and make sure it has at least the following:

<?php
$string['pluginname'] = 'The name of my plugin';

You will need to the purge the site caches or bump your plugin version number, in order for the name to appear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM