drupal-pattern-lab / roadmap

2 stars 0 forks source link

Consolidate Twig best practices #4

Open EvanLovely opened 7 years ago

EvanLovely commented 7 years ago

@evanmwillhite Originally wrote:

If possible, it would be great to consolidate examples of Twig/PL best practices into a single location(s). I can see possibly either both documentation and a Drupal starter kit (a la Drupal-Lab) or possibly even just one of those?

The only place I could see this getting hairy is if we differ too much on implementation, but if we can agree enough it would be nice to provide a good starting point for people new to this:

  1. Pattern Lab installation inside of Drupal
  2. Integrating multiple kinds of PL files (atoms, molecules, etc.) into multiple kinds of Drupal files (fields, nodes, views, paragraphs, blocks, bricks, etc.)
cybtachyon commented 7 years ago

To me this feels like two separate topics:

Twig Coding Standards

Twig Patterns Best Practices

To that end, I had drafted https://github.com/cybtachyon/twig-standards a bit ago and would like to offer it up as a place to separate out Twig Coding Standards.

evanmwillhite commented 7 years ago

You're absolutely right @cybtachyon - sorry about the vague wording. I meant specifically the implementation used within component-based theming using include, extends or embed. I often get questions about how to integrate Pattern Lab components with views, paragraphs, blocks (fill-in-the-blank Drupal thing), so I was talking about that specific piece.

That said though, thanks for sharing your Twig Coding Standards. I'll be sharing with our team - this is awesome!

sghoweri commented 7 years ago

While I personally think a catch-all "Twig/PL best practices" is a bit too broad, I could see a ton of value diving into several sub-topics / reoccurring themes through real world code examples, example plugin configurations, sample code snippets, dos and don'ts, known issues or workarounds, etc.

High level topics:

As a quick brain dump:

  1. General Twig coding standards (ie. how to write clean code that doesn't stink) -- like the coding standards doc @cybtachyon put together.
  2. Sample real world code using includes, embeds and extends (especially the latter two which don't seem to have a whole lot of examples out there) but also strategies on getting Pattern Lab isms w/ Twig extensions playing nicely with Drupal
  3. Common Twig hiccups (converting data, merging, setting data and data validation, cascading data / inheritance), especially with D8's Attributes object + ways this can be handled (using plugins but also other approaches)
  4. Ideas on some good component patterns / conventions (naming conventions for variables, nesting templates, handling template variations includes vs extends vs embeds on a single _template.twig, etc). Highly opinionated but examples of options could be helpful nonetheless. Folder structure / organization. Single folder containing all pattern files vs multiple folders per type.
  5. Real world examples on extending out of the box Twig functionality (functions, filters, custom tags, actual examples of writing Twig tests...) -- very few examples out there, let alone examples in the context of PL + Drupal