0
votes

I'll try to explain the question better... I am creating a sub theme from classy. I would like a way to pass variables into my theme via some kind of UI. I'm very new to Drupal 8 (and Drupal dev in general) so please let me know if you need more information.

For the record I am aware of preprocess function in Drupal however the variables I'm talking about wouldn't initially be set there...

For example... let's say I create a new node from a content type called basic page. I want a way that when I create a new basic page that there are options such as "number of columns; font-family; color scheme; etc" and I can define those on a per page basis. Then... in my theming I can dynamically look at the values set for the current page and render it accordingly. I come from a ColdFusion background with things such as request.page variables... so this is all new to me.

EDIT: I realize I could just add fields to the content type but I was told that adding fields to a content type that are metadata and not actual pertinent data to the content type is a bad practice.

Thanks for any help possible.

2

2 Answers

0
votes

I would look into the Paragraphs module. This will allow you a great deal of flexibility when it comes to design within the UI.

The Bootstrap Paragraphs bundle is another great option because it comes with pre-defined paragraphs out of the gate (including columns, accordion, etc). You can also easily add fields for color scheme, font family, etc, then in the templates just wrap the correct class and you're good to go.

0
votes

Another option is the Panelizer module. A bit more complex then the Paragraphs module, but in Drupal 8 more user-friendly (to the end-user) because of the live drag-and-drop feature on the page itself. Paragraphs provides a drag-and-drop feature on the edit form.

Another option is a custom module, that defines a config form. Maybe also create a field type that hold an node bundle (your content types name), a key and a value. Then use the preprocess hooks to get this config value and use it in your templates.