我正在开发基于 Moodle 的学习管理系统。我想为每封电子邮件添加电子邮件页眉和页脚。
我在 Moodle 中做了一些更改,以便在 ./lib/moodlelib.php 中添加图像,如下所示:
function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '', $attachment = '', $attachname = '',
$usetrueaddress = true, $replyto = '', $replytoname = '', $wordwrapwidth = 79) {
global $CFG, $PAGE, $SITE;
// Append image at top
if($messagehtml){
$tmp = $messagehtml;
// Added image here
$messagehtml = '<img src="'.$CFG->wwwroot.'/images/logo.png" alt="LMS" /><br/>';
// $messagehtml = $image;
$messagehtml .= $tmp;
}
if($messagetext){
$tmp = $messagetext;
// Added image here
$messagetext = '<img src="'.$CFG->wwwroot.'/images/logo.png" alt="LMS" /><br/>';
// $messagehtml = $image;
$messagetext .= $tmp;
}
....................
但我希望页眉和页脚作为固定模板。请帮助我。
您可以在 language 文件(英文直接在
/lang/en
下或在插件中)创建消息标题,然后在语言文件中添加以下字符串:
$string ['message_header'] = '<p> write here whatever your style and HTML structure you want in your header</p>
adding your image as well <img src="'.$CFG->wwwroot.'/images/logo.png" alt="LMS" />';
然后你也可以为你的页脚写一个字符串:
$string ['message_footer'] = 'Your HTML footer here';
最后你可以在消息中插入你的字符串:
$message = 'here your body';
// insert message header - if your language string is in /lang/moodle.php:
$message = get_string ( 'message_header') . $message;
// insert message footer - if your language string is in your /local/myplugin:
$message .= get_string ( 'message_footer', 'local_my_plugin' );
如果您直接在语言文件中(或在数据库中)更改页眉和页脚,则可以随意自定义页眉和页脚。请参阅此处)。
有点晚了,但我希望它能帮助别人: https://docs.moodle.org/dev/Themed_emails 只需在 /var/www/html/moodle/lib/templates 中查找电子邮件模板。名为 email_html.mustache 的模板应该是正确的。
或者,您可以使用在
Moodle Dev Template Documentation中指定的
pix
关键字。
有了这个功能,你可以通过主题文件夹(theme/yourtheme/pix/logo.png)或其他模块如core等上传图片
使用基于自定义主题提升的示例:
{{#pix}} logo, theme_yourtheme, Alt Text {{/pix}}
使用核心模块的例子:
{{#pix}} logo, core, Alt Text {{/pix}}
注意: 模板可以在
lib/templates
文件夹中找到。例如: