תבנית נושא Canvas

:information_source: Summary Quick start your theme design with a prepared theme template.
:busts_in_silhouette: Audience New developers that want to get started building themes for Discourse. Experienced developers that want to use a ready-made template.
:hammer_and_wrench: Repository Manuel Kostka / Discourse / Canvas / Canvas Theme Template · GitLab
:open_book: New to Discourse Themes? Beginner’s guide to using Discourse Themes

Canvas provides a flexible template that allows you to create custom themes with less coding. Easily adjust properties and configuration values to tailor a theme to your needs.

Example views


The base template retains default values and remains neutral in design.

Minimal adjustments that modify a few custom properties and define a highlight color:

A design that integrates the Topic Cards component and custom styles for banners:

An elaborate theme that includes a custom font and unique color schemes:

Usage


  1. Clone the Theme Template.

  2. Synchronize the theme with your Discourse instance using the discourse_theme gem.

  3. Go to the admin backend and manually adjust these theme component settings:
    Category Banners
    Plugin outlet → above-main-container
    Tag Banners
    Show below site header → uncheck
    Show above main container → check

  4. Edit scss/properties.scss to define values for custom properties

  5. Edit about.json to add assets, color schemes and more theme components

A closer look at the setup


The Canvas Theme template only extends the default theme skeleton with bundling a few theme components and adding some ready-made style files. The actual features are handled by a separate theme component Canvas Settings. This component serves two functions:

This split setup allows you to create a theme using the Canvas template, while still benefiting from ongoing fixes and updates provided through the component.

Example themes


You can preview shared example themes at https://canvas.kostka.studio. There’s a theme toggle at the bottom of the sidebar to change theme.

Review code of the shared example views or install them as your starter theme from these repositories:


:tada: A huge thank you to Discourse for sponsoring the development of this project!

25 לייקים

Those theme settings don’t show up when I tried to install the example themes. Is that expected behavior?

לייק 1

ההגדרות נמצאות ברכיב העיצוב מותקן כ-Canvas Settings. יכול להיות שזה קצת מבלבל שההגדרות תמיד נשמעות כ-Theme Settings בממשק המשתמש, גם ברכיבי העיצוב.

2 לייקים

Found them in Canvas Settings component, thx!

3 לייקים

Thanks so much for working on this @manuel.

I took the Editor version for a spin locally, it mostly works very well, but I noticed some small issues.


On a default install, without changing any settings, the tag label in the Extra Banners component shows up in the wrong place:

The category banner is also shown in the same place, above the sidebar. Latest topics, Hot topics are correctly shown in the main column.


I’m guessing it’s not a goal of the theme to fully cover the admin UI, however, the light and dark Editor color palettes have the admin sidebar looking quite different. I am curious if it is possible to harmonize with the non-admin sidebar.

5 לייקים

The theme is meant to show banners next to the sidebar, using the above-main-container outlet. The Extra-Banners component uses that outlet by default, but the two components for Category and Tag banners are by default rendered below the header. I wouldn’t want to fork these components, just to set a different default outlet… That’s why I put these instructions:

But if that’s easy to miss, maybe there’s a better way to put it? :thinking:

Yeah, that’s easy enough and seems a good approach for this theme. I just added a commit!

5 לייקים

אה כן, אני מבין איך הגענו לזה. אנחנו לא בהכרח רוצים לשנות את ההגדרות כברירת מחדל ברכיבי באנרים של קטגוריה/תג, גם לא רוצים לנתק אותם. זה קשה לתקן, בואו נישאר עם המצב הקיים בינתיים ונסתכל אם אחרים יתקל באותה בעיה.

השינוי בסיידבר החיובי נראה טוב כבר, תודה!

4 לייקים

Could these instructions be elaborated a bit? Is it not possible to just install from the admin UI? Thx :pray:t4:

EDIT: I installed via the admin UI and it seems to be working except there doesn’t seem to be anywhere to edit scss now

EDIT: nevermind, I see that is probably expected and you’re showing to edit the theme files directly. I wonder if it could be on the roadmap for this to happen via the admin ui? Like, have a variables editor same as you have a settings editor

3 לייקים

I don’t know what’s on the core roadmap, but one thing you could do right now is create a new theme component right on the admin UI:

And then declare custom properties on it’s CSS file. You could either look up properties on the Readme file. Or copy the contents of properties.scss from the theme repo.

2 לייקים

How do I clone this to Gihub? Still a bit on the green side :wink:

You could import it through the UI:

However, if you want to be able to sync changes, I believe you’d need to pull to a local clone and then push from it. Something like this:

  1. Clone from GitLab
git clone "https://gitlab.com/manuelkostka/discourse/canvas/theme.git"
  1. Set push URL to your GitHub repo
git remote set-url --push origin "git@github.com:Username/Reponame.git"
  1. Then you can periodically fetch from GitLab and push to GitHub
git fetch -p origin
git push origin
2 לייקים

I don’t see a plus on mobile on GitHub. May need to try the command lines when Home.

All I see in GitHub on dashboard is option to create a new repo but no claim ne option. I am on free account so not sure if that might have something to do with it.

I added a component that lets you define a few style variables and layout options right on the component ui:

It’s limited compared to declaring custom variables on the stylesheet. But it lets you tinker with a few different looks. Curious to hear if that works! :eyes:

2 לייקים

I’m playing with it right now and I think it’s nice! Is there a way to reduce the line spacing of the menu - to make it more compact?

Also, I can’t scroll the solid sidebar, is this by mistake?

2 לייקים

I just adjusted the CSS styles for the solid sidebar, scrolling should work again!

However, the solid sidebar is just one of the options on the Styles component I mentioned on the post above. If you want to adjust more styles (like spacing the sidebar menu), you’d need to follow the approach explained above in Usage and A closer look at the Setup: Use your own stylesheet with CSS custom properties – in this case that would be -d-sidebar-row-height.

3 לייקים

I’ve put together a new example theme based on this template. As the name suggests, this one’s a tribute to the original Central theme! :hugs: :partying_face:

I loved the layout and visual style of Central and I’ve been packaging some of its features into standalone components, like the Custom User Menu and several sidebar blocks.

I realized that with the sidebar and some styles, this template actually gets you a good way towards the original theme’s look and feel.


In any case, I’m not planning to fully re-build the Central theme.. but I might still experiment with a dedicated topic list style down the road. If you’re curious and want to take a look, the theme is also live here, select it using the sidebar theme toggle: https://canvas.kostka.studio

8 לייקים

מאוד נחמד. תודה על השיתוף.

לייק 1

תודה ששיתפת את התבנית הזו! הגמישות עם הרכיבים והעיצוב הנקי מקלים מאוד על ההתאמה האישית. מצפה לנסות אותה על המופע שלי.

2 לייקים

ברוכים הבאים ל-Discourse :discourse: !

2 לייקים