Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Additional classes for Paragraph items #63

Open
TobyWild opened this issue Feb 26, 2019 · 1 comment
Open

Additional classes for Paragraph items #63

TobyWild opened this issue Feb 26, 2019 · 1 comment

Comments

@TobyWild
Copy link

Paragraphs main wrapper class is only "field__item", which is also a class given to children.

So for a page that has a number of components down the page, and one of those items is an 'Item List', which has two generic 'Items' that are displayed as a two column layout.

However this means the main container has .field__item, the item list has .field__item, the item has .field__item

So if you target .field__item, it ends up cascading into all the fields, but this is also the only effective selector to control the layout of the elements.

It would be ideal if a delta for the paragraph could be added at this level, in order to more easily target specific containers.

Thoughts?

@Benjen
Copy link

Benjen commented Jun 13, 2019

@TobyWild I was having a similar issue on a project where I needed to style a particular page component on a page. I was not easily able to target that particular component as there was more than one component on the page. I ended up creating a preprocess function which adds a class "paragraph-id-ID" (e.g. paragraph-id-12) to the paragraph container.

/**
 * Implements hook_preprocess_HOOK().
 */
function govcms8_uikit_starter_preprocess_paragraph(array &$variables) {
  // Add class "paragraph-id-ID" to paragraph wrapper.
  $variables['attributes']['class'][] = 'paragraph-id-' . $variables['paragraph']->id();
}

I have created a pull request to include this functionality in the govcms8_uikit_starter theme.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants