Skip to main content
Documentation
On this page

Install Cirth for Symfony

AssetMapper, Symfony's default for front-end assets, can bring a stylesheet from an npm package without Node: importmap:require downloads it, and an import in assets/app.js links it on every page that renders the importmap.

Verified with Symfony 8.1.8 on

Five steps: create the project, require it, import it, write Twig and check it.

1 Create the project #

A web application from the Symfony skeleton comes with AssetMapper and Twig:

symfony new my-app --webapp
cd my-app

Without the Symfony CLI, composer create-project symfony/skeleton my-app and then composer require webapp give the same project.

2 Require it #

php bin/console importmap:require @cirthcss/cirth/dist/cirth.min.css

The file lands in assets/vendor/, and importmap.php records it with its version.

3 Import it #

At the top of assets/app.js, before the app's own stylesheet:

import "@cirthcss/cirth/dist/cirth.min.css";
import "./styles/app.css";

The importmap('app') call in templates/base.html.twig then writes a <link> for Cirth before the app's CSS, so assets/styles/app.css comes after it and can override --cirth-* properties. In production, php bin/console asset-map:compile copies the file unchanged under a digest.

4 Write Twig #

Form themes render labels and inputs Cirth styles as they are; the default form_div_layout.html.twig needs no Bootstrap theme:

{% extends 'base.html.twig' %}

{% block body %}
<main class="container">
  {{ form_start(form) }}
    {{ form_row(form.email) }}
    <button type="submit">Subscribe</button>
  {{ form_end(form) }}
</main>
{% endblock %}

5 Check it #

Put this forced-dark region in a page or component that uses the global stylesheet:

<section data-theme="dark">
  <article>
    <p>Dark, whatever the system scheme is.</p>
  </article>
</section>

Run the app, then open the page while the system uses a light theme. A dark article proves that Cirth loaded and that data-theme="dark" is working. It remains dark when the system switches to a dark theme.

Customization covers the --cirth-* properties; set yours in assets/styles/app.css. Package and builds lists the classless, scoped and print entry points. Return to Framework guides for another stack.

Symfony™ is a trademark of Symfony SAS. Cirth is not affiliated with or endorsed by Symfony SAS or the Symfony project.

Search documentation

Type at least two characters to search.