Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 2.43 KB

USECASE2.md

File metadata and controls

23 lines (18 loc) · 2.43 KB

Use case 2: Using PHP, Java, or another language for dynamic markup

  1. Read the Basic HTML Use Case instructions
  2. Download the supporting assets listed in the Basic HTML use case
  3. Include the supporting assets in whatever method that produces the HTML headers required by your dynamic templating system
  4. Use the sample HTML to get the markup required for the programmatically created output. For each component and template, view the pattern info in the settings cog.
  5. Take a look at the Twig templates and JSON data files in the relative pattern source directories. They will inform how and when to use variables within the markup: /source/_patterns/[atomic-level]/[component]/[component].twig (in the source repo).

Leveraging the Pattern Lab Twig templates

You may consider leveraging the Twig templates in Pattern Lab. There are many considerations with this approach.

Assume the Twig templates driving the Pattern Library as an example only and do not explicitly copy them into your custom repository and expect them to work.

Twig usage caveats

  1. The version of Twig used directly impacts the functionality of the Twig template code.
  2. Twig.js (Node.js), Twig (for PHP), Twig (for Drupal), and jTwig (for Java) all have different levels of >support for Twig syntax and functions. We ran into these differences and limitations in the creation of the Pattern Library and using Twig.js and the different affect the PHP version has on Twig support.
  3. The Pattern Lab / Pattern Library Twig templates includes variables and logic required to display various versions of elements and are influenced by the JSON data files. These variables may not exactly match what your custom solution needs.
  4. The Pattern Lab / Pattern Library Twig templates have been created to nest (create once, leverage everywhere) by being included in Twig blocks. This, for some reasons, may not be the best for your custom tool development or your application may require a different type or level of Twig block inclusion.
  5. You may need to add different logic to support your custom tool's needs at the display layer.

An example of a PHP file with a couple of Twig templates is included at /public/examples/php/README.md (in package repo) and at /source/examples/php/README.md (in source repo). Note: this example requires a Composer install to use and to ensure a compatible version of Twig is used. Read the example's README.md for more information.```