Download
Download the Metronic Integration Examples from our GitHub repository .
Please note that the sample project does not include the Metronic Tailwind CSS source files by default. You need to copy the Metronic assets from your downloaded Metronic folder to complete the integration.
Clone Integration Repository
git clone https://github.com/keenthemes/metronic-tailwind-html-integration.git cd metronic-tailwind-html-integration/metronic-tailwind-symfony
Copy Metronic Assets
assets
folder from the metronic-tailwind-html-demos/dist
directory into your Symfony project's assets/assets/
directory. The resulting structure should be assets/assets/
. # From your metronic-tailwind-html distribution cp -r metronic-tailwind-html-demos/dist/assets/* metronic-tailwind-symfony/assets/assets/ # Verify the structure ls metronic-tailwind-symfony/assets/assets/ # Should show: css/ js/ media/ vendors/ styles/
Install Dependencies
# Install dependencies composer install # Install additional packages if needed composer require symfony/asset-mapper composer require symfony/twig-bundle
Start Development Server
# Start the development server symfony serve # Or use PHP built-in server php -S localhost:8000 -t public/
http://127.0.0.1:8000
to see your Symfony app. You can explore both demo layouts: # Demo 1 - Sidebar Layout http://127.0.0.1:8000/demo1/ # Demo 2 - Header Layout http://127.0.0.1:8000/demo2/
If you prefer to create a project from scratch, follow the manual setup steps in the next sections.
Create Project
Install Symfony CLI
Create New Symfony Project
# Create new Symfony project symfony new metronic-tailwind-symfony --version="7.*" --webapp # Navigate to project directory cd metronic-tailwind-symfony
Install Required Dependencies
# Install AssetMapper for asset management composer require symfony/asset-mapper # Install additional packages for development composer require symfony/maker-bundle --dev composer require fakerphp/faker --dev
Configure Environment
# Copy environment configuration cp .env .env.local # Edit .env.local for your local settings # APP_ENV=dev # APP_DEBUG=true
Prepare Asset Directory
# Create assets directory structure mkdir -p assets mkdir -p assets/{css,js,media,vendors,styles} # Verify directory structure tree assets/ -L 3
Your Symfony project is now ready for Metronic integration. Continue to the next section to configure AssetMapper for Metronic assets.
Integrate Core
AssetMapper is Symfony's approach to asset management, replacing traditional build tools. Learn more at the official AssetMapper documentation .
Copy Metronic Assets
# Copy assets from Metronic distribution cp -r /path/to/metronic-tailwind-html-demos/dist/assets/* assets/assets/ # Verify asset structure ls -la assets/assets/ # Should contain: css/ js/ media/ vendors/ styles/
Update Main Asset Entry
assets/app.js
: // Import main styles from assets subdirectory import './assets/styles/app.css'; // Import any additional scripts as needed console.log('Metronic Tailwind CSS ready!');
Configure AssetMapper
assets/
directory. Verify the configuration: # Check discovered assets php bin/console debug:asset-map | head -20 # Check specific asset mapping php bin/console debug:asset-map app # Compile assets (optional for development) php bin/console asset-map:compile --dry-run
Create Demo Controllers
# Generate controllers php bin/console make:controller Demo1Controller php bin/console make:controller Demo2Controller
config/routes.yaml
: demo1_routes: resource: ../src/Controller/Demo1Controller.php type: attribute prefix: /demo1 demo2_routes: resource: ../src/Controller/Demo2Controller.php type: attribute prefix: /demo2
Core integration is complete! The AssetMapper will automatically handle asset versioning, caching, and HTTP/2 optimization for your Metronic assets.
Integrate Styles
For detailed Twig templating patterns and best practices, refer to the official Twig documentation .
Create Base Template Structure
# Create template directory structure mkdir -p templates/{partials,demo1/{partials},demo2/{partials}} # Create base templates touch templates/base.html.twig touch templates/demo1/base.html.twig touch templates/demo2/base.html.twig
Create Shared Partials
# Create shared partials touch templates/partials/head.html.twig # Meta tags, CSS, favicon touch templates/partials/scripts.html.twig # JavaScript includes touch templates/partials/theme-mode.html.twig # Theme mode toggle script
asset()
function. See the example partials in the repository. Setup Demo1 Layout (Sidebar)
# Create Demo1 layout partials touch templates/demo1/partials/sidebar.html.twig # Main navigation sidebar touch templates/demo1/partials/header.html.twig # Top header bar touch templates/demo1/partials/footer.html.twig # Page footer # Create Demo1 pages touch templates/demo1/index.html.twig
data-kt-drawer
components for responsive navigation. Setup Demo2 Layout (Header)
# Create Demo2 layout partials touch templates/demo2/partials/header.html.twig # Main header with logo touch templates/demo2/partials/navbar.html.twig # Navigation menu touch templates/demo2/partials/toolbar.html.twig # User toolbar touch templates/demo2/partials/footer.html.twig # Page footer # Create Demo2 pages touch templates/demo2/index.html.twig
data-kt-header
and data-kt-toolbar
components for horizontal navigation. Configure Asset References
assets/
structure: {# Example asset references in templates #} <link href="{{ asset('vendors/keenicons/styles.bundle.css') }}" rel="stylesheet"/> <link href="{{ asset('css/styles.css') }}" rel="stylesheet"/> <script src="{{ asset('vendors/apexcharts/apexcharts.min.js') }}"> </script> <script src="{{ asset('js/core.bundle.js') }}"> </script>
Reference HTML Layouts
# Demo1 - Sidebar Layout metronic-tailwind-html-demos/dist/html/demo1/index.html # Demo2 - Header Layout metronic-tailwind-html-demos/dist/html/demo2/index.html
Template integration complete! Your Symfony application now features both Metronic demo layouts with proper asset loading and dynamic content support.
For complete template examples and advanced component integration, explore the templates directory in the repository.
Convert Layouts
This conversion process focuses on the structural transformation from HTML to Twig. For advanced Twig templating techniques, refer to the official Twig documentation .
Analyze HTML Structure
# Demo1 Structure - Sidebar Layout metronic-tailwind-html-demos/dist/html/demo1/index.html ├── <head> - Meta tags, CSS, favicon ├── <body class="demo1 kt-sidebar-fixed kt-header-fixed"> │ ├── Theme Mode Script │ ├── Sidebar (<div class="kt-sidebar">) │ ├── Header (<div class="kt-header">) │ ├── Main Content (<main class="kt-content">) │ └── Footer (<div class="kt-footer">) └── JavaScript includes # Demo2 Structure - Header Layout metronic-tailwind-html-demos/dist/html/demo2/index.html ├── <head> - Meta tags, CSS, favicon ├── <body class="[--header-height:100px]"> │ ├── Theme Mode Script │ ├── Header (<header class="h-(--header-height)">) │ ├── Main Content (<main class="flex grow flex-col">) │ └── Footer (<div class="kt-footer">) └── JavaScript includes
Extract Base Template
# Extract shared partials from HTML head section templates/partials/head.html.twig # Meta tags, CSS links, favicon templates/partials/theme-mode.html.twig # Theme switching script templates/partials/scripts.html.twig # JavaScript includes # Create base template hierarchy templates/base.html.twig # Root template with common structure templates/demo1/base.html.twig # Demo1-specific layout templates/demo2/base.html.twig # Demo2-specific layout
Create Layout Partials
# Demo1 Sidebar Layout Components templates/demo1/partials/sidebar.html.twig # Navigation sidebar with kt-sidebar templates/demo1/partials/header.html.twig # Top header bar with kt-header templates/demo1/partials/footer.html.twig # Page footer # Demo2 Header Layout Components templates/demo2/partials/header.html.twig # Main header with logo and navigation templates/demo2/partials/navbar.html.twig # Navigation menu components templates/demo2/partials/toolbar.html.twig # User toolbar and actions templates/demo2/partials/footer.html.twig # Page footer
Convert Body Structure
{# Demo1 Body Structure Example #} <body class="antialiased flex h-full demo1 kt-sidebar-fixed kt-header-fixed"> {{ include('partials/theme-mode.html.twig') }} <div class="flex grow"> {{ include('demo1/partials/sidebar.html.twig') }} <div class="kt-wrapper flex grow flex-col"> {{ include('demo1/partials/header.html.twig') }} <main class="kt-content flex grow flex-col"> {% block content %}{% endblock %} </main> {{ include('demo1/partials/footer.html.twig') }} </div> </div> </body> {# Demo2 Body Structure Example #} <body class="antialiased flex h-full [--header-height:100px]"> {{ include('partials/theme-mode.html.twig') }} <div class="flex grow flex-col"> {{ include('demo2/partials/header.html.twig') }} <main class="flex grow flex-col"> {% block content %}{% endblock %} </main> {{ include('demo2/partials/footer.html.twig') }} </div> </body>
Handle Asset References
{# Convert HTML asset references to Symfony asset() function #} <!-- Original HTML --> <link href="assets/vendors/keenicons/styles.bundle.css" rel="stylesheet"/> <script src="assets/js/core.bundle.js"> </script> <!-- Converted Twig --> <link href="{{ asset('vendors/keenicons/styles.bundle.css') }}" rel="stylesheet"/> <script src="{{ asset('js/core.bundle.js') }}"> </script> {# Update image sources #} <!-- Original HTML --> <img src="assets/media/app/default-logo.svg"/> <!-- Converted Twig --> <img src="{{ asset('media/app/default-logo.svg') }}"/>
Layout conversion complete! Your Metronic HTML layouts are now fully integrated as Symfony Twig templates with proper asset handling and component structure.
For complete converted template examples and advanced integration patterns, explore the templates directory in the repository.