Code Monkey home page Code Monkey logo

attach-library-twig-extension's Introduction

attach-library-twig-extension

Twig function that lets Pattern Lab use a simple version of Drupal's attach_library function to add CSS or JavaScript files per component.

Requirements

  1. Place the pl_attach-library.function.php file in the pattern-lab/source/_twig-components/functions directory.
  2. Add themePath: '/themes/my-awesome-theme into the pattern-lab/config/config.yml configuration file. Modify the path to point to the root of your theme.

Since this function is specifically for Pattern Lab (Drupal has its own), it is namespaced with pl_ so if you're using the Unified Twig Extensions module, it will ignore it when syncing functions between Drupal and Pattern Lab.

Usage

Simply add {{ attach_library(THEME/LIBRARYNAME) }} to any component Twig file using the same syntax as Drupal. Pattern Lab will then locate the theme's *.libraries.yml file and load the file from the path in that library whenever that component is loaded. Since this function uses the same syntax as Drupal, nothing else needs to be done when loading the component in Drupal. It will work as it always did!

Current Limitations

This function will not load dependencies. If you need to load a dependency or other file in Pattern Lab, it can be done as usual in /meta/foot.twig. See the commented out parts in Emulsify's file for examples of how to do this.

attach-library-twig-extension's People

Contributors

philwolstenholme avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.