简体   繁体   中英

Possible to Customize Profile Page on Moodle without touching core?

Is there a way to customize the profile page in moodle without editing the core files? Is it possible to override the page and keep the edits within the theme files? similar to how overriding a renderer keeps all the edited render files inside of the theme folder?

You could use the the $CFG->customscripts setting to use a copy of profile.php :

create a customscripts folder

yourmoodlesite/customscripts

Then set

$CFG->customscripts = 'yourmoodlesite/customscripts';

Then create a user folder in customscripts and copy profile.php so you have

yourmoodlesite/customscripts/user/profile.php

and remove or comment out the require...config.php line.

Now Moodle will use /customscripts/user/profile.php when viewing a profile.

Have a look yourmoodlesite/config-dist.php for more details

It depends what you want to change. If it is field names, then you can override the language strings via the admin interface.

If it is adding new custom fields, then that can be done via admin > users.

If it is hiding fields, then that should be possible with some custom CSS rules.

Other than that, you probably need to do some custom core changes (or start messing around with the page layout using javascript, injected via the theme).

I was able to achieve what I was trying to do by building a custom layout in my theme for mypublic.php, then inside this theme I included another php file that displayed all the attributes I wanted via global variables:

<?php
       echo '<div id="profilename" class="col-sm-6">';

        function get_content () {
        global $USER, $CFG, $SESSION, $COURSE;
        $wwwroot = '';
        $signup = '';}

        if (empty($CFG->loginhttps)) {
            $wwwroot = $CFG->wwwroot;
        } else {
            $wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
        }


       if (!isloggedin() or isguestuser()) {
       echo '<a href="'.$CFG->wwwroot.'/login/index.php">'.get_string('loggedinnot').'</a>';
       echo '</div>';
       echo '</div>';

       } else {
        echo '<ul id="custom_profileinfo">';

        echo '<li><span>'.get_string('username').': </span>'.'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$COURSE->id.'">'.$USER->username.'</a></li>';
        echo '<li><span>'.get_string('firstname').': </span>'.'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$COURSE->id.'">'.$USER->firstname.'</a></li>';
        echo '<li><span>'.get_string('lastname').': </span>'.'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$COURSE->id.'">'.$USER->lastname.'</a></li>';
        echo '<li><span>'.get_string('email').': </span>'.'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$COURSE->id.'">'.$USER->email.'</a></li>';
        echo '<li><a class="edit_profile" href="'.$CFG->wwwroot.'/user/edit.php?id='.$USER->id.'&amp;course='.$COURSE->id.'">'.get_string('updatemyprofile').'</a></li>';
        echo '</ul>';
        echo '</div>';
        echo '</div>';
       }

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