Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Talk:Creating a theme based on boost: Difference between revisions

From MoodleDocs
(Created page with "'''Note on loading presets''' This section of code in settings.php (I've slightly modified it) does not seem to load preset files from a folder in the theme root called preset...")
 
No edit summary
Line 1: Line 1:
'''Note on loading presets'''
'''Note on loading presets'''
This section of code in settings.php (I've slightly modified it) does not seem to load preset files from a folder in the theme root called preset and insert them into the drop-down list.
This section of code in settings.php (I've slightly modified it) does not seem to load preset files from a folder in the theme root called preset and insert them into the drop-down list.
Damyon: No - this code loads the preset files from a Moodle filearea named 'preset' - which is attached to the admin setting where you can upload more presets. If you want to load them from the files system you will need to do something closer to what the plain and default presets are doing.


<pre>
<pre>

Revision as of 01:40, 24 January 2017

Note on loading presets This section of code in settings.php (I've slightly modified it) does not seem to load preset files from a folder in the theme root called preset and insert them into the drop-down list.

Damyon: No - this code loads the preset files from a Moodle filearea named 'preset' - which is attached to the admin setting where you can upload more presets. If you want to load them from the files system you will need to do something closer to what the plain and default presets are doing.

$files = $fs->get_area_files($context->id, 'theme_boostbase', 'preset', false, 'itemid, filepath, filename', false);
    $choices = [];
    foreach ($files as $file) {
        $f = $file->get_filename();
        $choices[$f] = $f;
    }
    $choices['preset-morecandy.scss'] = 'preset-morecandy.scss';
    $choices['preset-morecandyiip.scss'] = 'preset-morecandyiip.scss';    

Note I've changed it slightly in an attempt to trace through what's happening. When explicitly inserted as above, they will appear in the drop-down. However, then there is a problem getting them to actually load in the lib function

function theme_boostbase_get_main_scss_content($theme)

Again I've altered the code a bit:

$context = context_system::instance();
    if ($filename == 'default.scss') {
        // We still load the default preset files directly from the boost theme. No sense in duplicating them.
        $scss .= file_get_contents($CFG->dirroot . '/theme/boost/scss/preset/default.scss');
    } else if ($filename == 'plain.scss') {
        // We still load the default preset files directly from the boost theme. No sense in duplicating them.
        $scss .= file_get_contents($CFG->dirroot . '/theme/boost/scss/preset/plain.scss');

    } else if ($filename) {
        // Check the preset file area for theme_boostbase.
        $presetfile=null;
        $presetfile = $fs->get_file($context->id, 'theme_boostbase', 'preset', 0, '/', $filename);
        if($presetfile) {
          $scss .= $presetfile->get_content();
        }
    } else {
        // Safety fallback - maybe new installs etc.
        $scss .= file_get_contents($CFG->dirroot . '/theme/boost/scss/preset/default.scss');
    }

In this case it doesn't load any content from the file (loses all theming) and doesn't fallback to safety either. Any ideas appreciated if someone has seen the same issue.

Also apologies if this is the wrong place to post this (as opposed to a theme forum or Damyon's github).

09:16, 24 January 2017 (AWST)