Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

Quark: Using SVG as custom logo

first-time theme

Started by Ryan Boyd 5 years ago · 2 replies · 1700 views
5 years ago

Quark's default logo -- grav-logo.svg -- gets embedded into the final HTML file produced and, as a result, can be influenced and changed through custom.css styes.

When one uploads a custom SVG logo, however, that file instead gets referenced as an image file (<img src="customlogo.svg">) which is NOT customizable by CSS in the custom.css file (based on current working knowledge and experience).

I seek this customization because I want the logo to be able to switch back and forth between a dark version against a white background (my default) into a light version that can exist well on top of hero-enabled pages with header transparency that use dark images.

I hope I described the issue well and look forward to any tips you might have.

RB

5 years ago

@ryanboyd, Unfortunately, Quark expects the custom_logo to be an image instead of svg.

What you can do:

  • Create a new theme inheriting from Quark
  • Copy file /user/themes/quark/partials/logo.html.twig to folder /user/themes/your-theme/templates/partials
  • Replace lines 4 + 5 with either a generic solution using svg_image():
    TWIG
    {{ svg_image('theme://images/logo/' ~ (logo|first).name) | raw }}
    

    or using a Quark specific solution:

    TWIG
    {% include('@images/logo/' ~ (logo|first).name) %}
    

    The new template will now look like:

    TWIG
    {% set logo = theme_var(mobile ? 'custom_logo_mobile' : 'custom_logo') %}
    <a href="{{ home_url }}" class="navbar-brand mr-10">
    {% if logo %}
    {{ svg_image('theme://images/logo/' ~ (logo|first).name) | raw }}
    {% else %}
    {% include('@images/grav-logo.svg') %}
    {% endif %}
    </a>
    
👍 1
last edited 09/18/21 by pamtbaau
5 years ago

Got it — that Quark as currently built expects a traditional pixel image (JPG, PNG, etc) versus an SVG. That makes sense.

A solution to my problem coming through a custom template tweak makes sense, too. Luckily, I've had some luck getting a Quark-inherited theme going, so I'll use this as a chance to start going deeper on the Twig.

Thank you for the suggestion, @pamtbaau. I'll try this out in the next few days and report back with a success/failure update.

Stay tuned.

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 193 2 months ago
Themes & Styling · by Ian, 2 months ago
3 90 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 449 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 44 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 123 3 months ago