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
 
(2 intermediate revisions by 2 users not shown)
Line 2: Line 2:
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.


<pre>
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';   
</pre>


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-downHowever, then there is a problem getting them to actually load in the lib function
Richard: OK, so hard-code them as for BoostOtherwise you would create a setting for uploading and saving presets in the theme file area that duplicates pretty much what is already being done with the Moodle filearea.  Got it, I think.


<pre>
I'll take away all my junk then... (still in the history if anyone wants it).
function theme_boostbase_get_main_scss_content($theme)
</pre>


Again I've altered the code a bit:
09:16, 24 January 2017 (AWST)
 
<pre>
$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');
    }


</pre>
While going through this tutorial I got a lot of error messages about missing strings. I needed to either turn off language string cache or purge the cache regularly. Maybe this is tripping others also, and should be mentioned? Regards, [[User:Samuli Karevaara 2|Samuli Karevaara 2]] ([[User talk:Samuli Karevaara 2|talk]])
 
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)

Latest revision as of 11:58, 28 June 2018

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.

Richard: OK, so hard-code them as for Boost. Otherwise you would create a setting for uploading and saving presets in the theme file area that duplicates pretty much what is already being done with the Moodle filearea. Got it, I think.

I'll take away all my junk then... (still in the history if anyone wants it).

09:16, 24 January 2017 (AWST)

While going through this tutorial I got a lot of error messages about missing strings. I needed to either turn off language string cache or purge the cache regularly. Maybe this is tripping others also, and should be mentioned? Regards, Samuli Karevaara 2 (talk)