ameotoko/contao-encore-bridge

1.0.3 2022-09-17 17:42 UTC

This package is auto-updated.

Last update: 2024-04-18 01:48:54 UTC


README

This is an extension for Contao CMS which provides a wrapper for Webpack Encore bundle's encoreEntryLinkTags() and encoreEntryScriptTags() functions, allowing a developer to use those functions in .html5 templates as well.

Installation

NOTE: Webpack Encore Bundle requires output_path config to be set. If you do not yet have Webpack Encore Bundle installed, Contao-Encore Bridge will add it to your application automatically, so be sure to set output_path in your config.yml file before installation:

# config/config.yml
webpack_encore:
    output_path: '%kernel.project_dir%/public/build'

Then install Contao-Encore Bridge:

composer require ameotoko/contao-encore-bridge

Configuration

Configure your Webpack Encore as described in official docs:

Usage

Assuming you have configured your Webpack entrypoint like this:

// webpack.config.js
const Encore = require('@symfony/webpack-encore');

Encore
  .addEntry('app', './frontend/js/app.js')
;

you can now output all stylesheets and scripts for that entry in your .html5 templates, e.g. in fe_page.html5:

<!DOCTYPE html>
<html lang="<?= $this->language ?>"<?php if ($this->isRTL): ?> dir="rtl"<?php endif; ?>>
<head>
    ...
    <?= $this->encoreEntryLinkTags('app') ?>
</head>
<body>
    ...
    <?= $this->mootools ?>
    <?= $this->encoreEntryScriptTags('app') ?>
</body>
</html>

Or add them from any other template like so:

<?php $this->extend('ce_gallery'); ?>

<?php $this->block('content'); ?>
    <?php $this->parent(); ?>

    <?php $GLOBALS['TL_CSS'][] = $this->encoreEntryLinkTags('app'); ?>
    <?php $GLOBALS['TL_BODY'][] = $this->encoreEntryScriptTags('app'); ?>
<?php $this->endblock(); ?>