如何在 HTML 块中创建一个 link 以在 URL 中动态插入配置文件字段?

How do I create a link in an HTML block that dynamically inserts profile fields in the URL?

我希望能够在 Moodle 中创建一个链接到 Google 表单的块。但是,该块需要从用户的个人资料中插入一些信息。具体来说,用户名、身份证号码和时间。我知道如何创建 Google 表单并使用 "Fillable Link."

我怎样才能完成这个任务?它也可以插入到主题的菜单中。

您需要创建 "block" 类型的新插件,如 here 所述。 如果你只需要插入一些 HTML 甚至基本的 PHP 东西,你只需要两个文件。

  1. 在 Moodle "blocks" 目录中创建一个新文件夹,示例 /var/www/moodle/blocks/googleform

  2. 在这个新目录中,创建一个名为 version.php 的文件。示例:

defined('MOODLE_INTERNAL') || die();
$plugin->version   = 2017051500;
$plugin->requires  = 2017050500;
$plugin->component = 'block_googleform';
  1. 在同一目录下,创建一个block_googleform.php文件:

defined('MOODLE_INTERNAL') || die();
class block_googleform extends block_base {
    public function init() {
        $this->title = get_string('pluginname', 'block_googleform');
    }

    public function get_content() {
        global $USER;
        $username = $USER->username;
        $userid = $USER->id;

        $this->content = "put your Google form here";
        return $this->content;
    }
}

然后,访问您的 Moodle 主页,让软件猜测您创建了一个新插件。安装它并尝试添加类型为 "googleform".

的块实例

如果您更喜欢只依赖您的主题,您可以尝试在 PHP 布局文件中使用相同的全局 $USER 信息。