Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Including One Pattern Within Another

Dave Olsen edited this page Jul 6, 2013 · 3 revisions

To use one pattern within another, for example to create a molecule from several atoms, you can either use:

  • a shorthand partials syntax or
  • the default Mustache partials syntax.

The Shorthand Partials Syntax

The shorthand partials syntax mimics the format that was found in the inc() function from the original version of Pattern Lab. It allows for partials to be less verbose than the default Mustache partials syntax. The shorthand syntax uses the following format:

{{> [patternType]-[patternName] }}

For example, let's say we wanted to include the following pattern in a molecule:

atoms/images/landscape-16x9.mustache

The pattern type is atoms and the pattern name is landscape-16x9. Pattern sub-types are never used in this format. The shorthand partial syntax would be:

{{> atoms-landscape-16x9 }}

The shorthand syntax also allows for fuzzy matching on pattern names. This means that, if you feel your pattern name is going to be unique within a given pattern type, you can supply just the unique part of the pattern name and the partial will be included correctly. For example, using the shorthand syntax this partial could be written as:

{{> atoms-16x9 }}

Important: If you include 16x9 in another pattern the PHP version of Pattern Lab may find that first depending on how your patterns are organized.

The Default Mustache Partials Syntax

The PHP version of Pattern Lab also supports the default Mustache partials syntax if you need more specificity when adding partials to your templates. The syntax is simply the path to the partial minus the .mustache extension. For example, let's say we wanted to include the following pattern in a molecule:

atoms/images/landscape-16x9.mustache

The default Mustache partial syntax would be:

{{> atoms/images/landscape-16x9 }}
Clone this wiki locally