Totara Learn Open Discussions

Building new themes on which parent theme? Ventura or legacy?

 
Michael Gregor
Building new themes on which parent theme? Ventura or legacy?
על ידי Michael Gregor בתאריך 22/10/2020, 01:25
קבוצה Partners

Hi,

I have already created several themes for Totara 9 - 12 and now I want to create a new theme for Totara 13. But I'm still a bit unsure about the new structure in 13. I have already looked at the various webinars and Q&A. Nevertheless I still have some open questions:

Should I create a new theme with the parent themes legacy and base or should I choose the ventura theme as parent? Ventura itself uses both of these themes as parents.

I would also like to know if legacy will be supported for older themes for a longer period of time, since ventura itself is also based on them?

And finally: Do I have to use the new functions and components in the /client/ folder or can I create a theme as before?

Thanks

Michael

Dave Wallace
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Dave Wallace בתאריך 22/10/2020, 14:31
קבוצה Totara

Hi there Michael, good questions, and they'll be covered with documentation shortly - we're just at the tail end of finishing those off. As they're not published yet, I'll answer your questions below (answers mostly from the docs):

> Should I create a new theme with the parent themes legacy and base or should I choose the ventura theme as parent? Ventura itself uses both of these themes as parents.

You can do either, the Ventura theme mostly does a handful of things:

  1. Overrides colours that are defined in `/client/tui/src/global_styles/*`
  2. Has a generated `css_variables.json` file that describes the variables that it uses, and relationships between them
  3. Provides an entry point for the "Theme Settings" UI in the Appearance Admin menu
  4. Provides some default images, stored in `/server/theme/ventura/`
  5. Serves as an example of a theme that you can inherit from, or build your own

To inherit from Ventura, you'll need (in `/server/`):

  • `server/theme/mytheme/config.php`
  • `server/theme/mytheme/lang/en/mytheme.php`
  • `server/theme/mytheme/version.php`

Yes, your theme inheritance chain should be: `$THEME->parents = ['ventura''legacy''base'];`

If you want to enable the Theme Settings page for your custom theme, you'll also need to copy the following files from Ventura:

  • index.php
  • lib.php
  • settings.php
In all instances apart from the theme inheritance chain, be sure to use your theme's name, not Ventura .

Then, for `/client/`, this can be done in one step by running `npm run tui-init theme_mytheme vendor` (where `vendor` is a unique string identifying your organisation. Lowercase is suggested for ease of typing - Totara internal components use "totara" for example).

At this point you're now ready to start customising.

In order to customise component CSS, template, or functionality, you can add a component file in a special location where it will be picked up by the override system. 

To inherit from Legacy only, follow the same steps as above, but remove "ventura" from the array in config.php.

After completing the instructions above, you can add your theme customisations in the following places:

  • `client/component/my_theme/global_styles/_variables.scss` (variable overrides)
  • `client/component/my_theme/global_styles/static.scss` (global CSS rules)

You can also break up your variables or global CSS rules into multiple files and Use the `@import` syntax to include them. `@import 'my_theme/xyz'` maps to `client/component/my_theme/global_styles/xyz`. You can see this in action at `client/component/tui/src/global_styles/_variables.scss`.

Any Vue component can be extended in a theme by creating a file in the right folder.

The pattern for override files is: `client/component/theme_(themename)/src/(subfolder)/overrides/(original client/component/* subfolder)/(rest of path)`

For example, if the component you want to extend is: `tui/components/buttons/Button`, you would create `client/src/theme_mytheme/components/overrides/tui/buttons/Button.vue`.


> I would also like to know if legacy will be supported for older themes for a longer period of time, since ventura itself is also based on them?

Legacy is a "stopgap" theme, for visual compatibility between Totara Learn and Totara Engage/Totara Perform. It will likely be around for a while, as there is so much of Totara Learn that we could convert, we can't convert it all in one go, so Legacy will be needed to continue bridging visual consistency.


> Do I have to use the new functions and components in the /client/ folder or can I create a theme as before?

If you're only touching CSS, then you could create a theme only in `/server/` and supply specific CSS overrides following whatever file structure you want. You can do this because although the Tui framework components are all isolated in their construction - ultimately all the CSS is output onto the page in the global scope. So long as you're working with the CSS cascade and specificity concepts correctly, you should be able to override selectors.

As soon as you want to make use of the benefits of overriding or extending markup, javascript etc, and the benefits of expressing variables in the "theme Settings" UI, then working within our intended implementation will cause less friction.

Dave Wallace
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Dave Wallace בתאריך 28/10/2020, 17:31
קבוצה Totara

Ah, Michael one more thing sorry, caching settings have changed for the new Tui framework.

You will need to add `

$CFG->forced_plugin_settings['totara_tui'] = ['cache_js' => false, 'cache_scss' => false, 'development_mode' => true];
` (also available in the UI: /admin/settings.php?section=totara_tui_settings)
Michael Gregor
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Michael Gregor בתאריך 12/11/2020, 09:39
קבוצה Partners
Hi Dave,

thank you very much, your post helped me a lot!

But one more question:

You wrote:
"In order to customise component CSS, template, or functionality, you can add a component file in a special location where it will be picked up by the override system. "

But is there still a way to customise mustache templates on server side?

I tried to customize the totara menu by overriding the template file (nav_primary.mustache) from totara_core within my theme folder (on /server/) but I had no luck with that. Is there something I am missing?

Thanks
Dave Wallace
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Dave Wallace בתאריך 12/11/2020, 13:17
קבוצה Totara

No worries Michael, happy to help.

You should be able to continue using Mustache overrides, and in the server directory for Themes, yes. We re-tested this morning and we were able to successfully:

  • create a file at server/theme/mytheme/templates/totara_core/nav_primary.mustache 
  • render the override template when switching to `mytheme`
  • do the above with the following Theme inheritance stacks: ventura, legacy, base and legacy, base and just legacy

In the first instance you might try:

  • triple-check your path to the override template (old stack overrides in old server/ directory structure, new stack overrides in new /client directory structure)
  • do clear caches, purge caches possibly too. The old stack cache settings are still required for changes made to the old stack, by the way.

Also, the front end docs have just been published, I recommend having a read through, even though we've covered a bunch of Theme-related info in this thread already. The link to the new docs is: https://help.totaralearning.com/display/DEV/Tui+front-end+framework

Let me know how you get on.

Michael Gregor
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Michael Gregor בתאריך 23/11/2020, 06:49
קבוצה Partners
Thank you Dave, again that worked great! :) I was using the wrong folder ("core" instead of "totara_core"), so it was my fault. Works perfectly now, thanks!

One (hopefully) last thing:

Thanks for the frontend docs. They are really helpful. But one point I still don't quite understand though: Is SCSS parsed on-demand by the server, as it was with LESS before, or not? I have created a scss file for my theme and put the name under "sheets" in the theme's config.php. Also a directory /scss/ and a directory /style/ with a file.scss and a file.css.

Despite activated designer mode and deactivated SCSS caching, the scss file is ignored. Only the .css file of the same name in the /css/ folder is being used. Have I understood something wrong?

Michael Gregor
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Michael Gregor בתאריך 8/12/2020, 23:57
קבוצה Partners

Hey Dave,

may I remind you of my last question regarding the SCSS? Unfortunately I have not yet found a solution.


Thanks

Michael

Dave Wallace
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Dave Wallace בתאריך 13/01/2021, 13:21
קבוצה Totara

Michael, so sorry to have missed this, I only spotted it after coming back from annual leave and thoroughly backwards trawling emails and forums to get back up to speed. My humblest apologies if we've left you in a tricky spot.

Did you manage to get things working? If you can let me know, and if you still need a hand we'll take a look ASAP.

Michael Gregor
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Michael Gregor בתאריך 14/01/2021, 00:18
קבוצה Partners

Hi Dave,

thank you for your answer. It was perfect timing, because I wanted to address the issue again today. Unfortunately, I have not yet managed to find an adequate solution in the meantime. So I would be happy about any tips.

Thanks,

Michael

Dave Wallace
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Dave Wallace בתאריך 14/01/2021, 17:01
קבוצה Totara

Alrighty, what we have now works like this:

  • Legacy: precompiled with Grunt. SCSS not re-compiled on the fly.
  • Tui: precompiled. Re-compiled on-demand.

Currently the only on-demand re-compilation happens when Theme Settings are changed, or the Theme file revision changes, or the caches are Purged.

We have recently published an Example theme by the way, you can take a look at that for any pointers on where things should live. In that Theme, and so I suspect also in your Theme, SCSS files that live in `/client/component/theme_yourthemename/src/global_styles/` will be picked up by the new Tui `npm` compile commands, as well as be re-compiled on the fly as described above.

Within `/server/theme/yourthemename/` you can still have a `scss` directory, and when you have run `npm install` and `npm install grunt-cli -g` when in `/server/` (different npm packages from `/`) you then compile with `grunt sass`.

In the attached screenshot I've checked each source, including the older 'sheets' inclusion method, to confirm things are working.

The link to the Example theme is here: https://git.totaralearning.com/projects/EXAMPLE/repos/theme_example/browse

I'll add the 'sheets' way of doing things into the `/server/` part of the example, to show that it still works as a way to include CSS files, however aiming to pull things into `/client/` area of the Theme is where we'd put things, to be explicitly clear about the delineation of front and back end code.


Michael Gregor
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Michael Gregor בתאריך 14/01/2021, 23:52
קבוצה Partners

Thanks Dave! I'm going to have a look at the example theme.

So did I get it right? If I do not use the /client/ side for my theme, I have to compile the SCSS on the /server/ side manually with grunt and no on-the-fly-compilation is done? (Even not after purging the caches).



Dave Wallace
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Dave Wallace בתאריך 17/01/2021, 14:55
קבוצה Totara

Yeah that's right, when we used LESS the on-the-fly part was terribly slow, and when we ported to SCSS we decided to no longer use the /server/ directory for front end dependencies. In theory you could get the scssphp lib to process your dependencies in /server/ again, and we have made a couple of improvements to it; large file handling and source map support. However I'd just recommend following the new convention in case you end up in a situation where file load order changes because of different compilation paths and timings, etc.

Dave Wallace
Re: Building new themes on which parent theme? Ventura or legacy?
על ידי Dave Wallace בתאריך 30/09/2024, 13:04
קבוצה Totara

Hi, just a quick note here to say that we've moved the Example Theme code to Github: https://github.com/totara/theme-plugin-example

Our front-end documentation will always have the most up-to-date information about these things too.


Cheers,

Dave