Currently, i'm using a taxonomy field to manage CSS Classes for a couple of my test paragraphs. Eg:
{% if content.field_color_scheme[0]['#title'] == 'blue' %}
{% set color_scheme_class = 'col-bg-blue' %}
{% elseif content.field_color_scheme[0]['#title'] == 'red' %}
{% set color_scheme_class = 'col-bg-red' %}
{% elseif content.field_color_scheme[0]['#title'] == 'lightgrey' %}
{% set color_scheme_class = 'col-bg-light-grey' %}
{% endif %}
<section class="p-y-3 {{color_scheme_class}}">
<div class="container">
<div class="row">
<div>Can you write better documentation for someone to get started with Classy Paragraphs. I've installed the module, added a couple Classy Paragraphs, created a reference field etc but i can't select a css class from my referenced paragraph. A blog post or better documentation would definitely help me or other individuals that are experimenting with the Paragraphs Module and trying to determine the best way to solve certain problems.
One way i'm using Taxonomy Fields is to add conditional layouts based on a Selection....eg: Four Column Cards or Three Column Cards, i'm wondering if i can just create the classes using the Classy Paragraphs module with a Key|Value....similiar to a select list. Eg: The User can Select "Four Columns" but the bootstrap "col-md-3" class is printed.
Sample Code that i'm using that works.....
{%
set classes = [
'paragraph',
'paragraph--type--' ~ paragraph.bundle|clean_class,
view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
]
%}
{% if content.field_card_columns[0]['#title'] == '3' %}
{% set columns = 'col-md-4' %}
{% elseif content.field_card_columns[0]['#title'] == '4' %}
{% set columns = 'col-md-3' %}
{% endif %}
{% if content.field_color_scheme[0]['#title'] == 'blue' %}
{% set color_scheme_class = 'col-bg-blue' %}
{% elseif content.field_color_scheme[0]['#title'] == 'red' %}
{% set color_scheme_class = 'col-bg-red' %}
{% elseif content.field_color_scheme[0]['#title'] == 'lightgrey' %}
{% set color_scheme_class = 'col-bg-light-grey' %}
{% endif %}
<section class="p-y-3 {{color_scheme_class}}">
<div class="container">
<div class="row">
<div>
<div{{ attributes.addClass(classes) }}>
{% for key, item in content.field_cards if key|first != '#' %}
<div{{ attributes.addClass(columns) }}>
<div class="item-{{ key + 1 }}">{{ item }}</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</section>| Comment | File | Size | Author |
|---|---|---|---|
| #7 | classy_paragraphs-better-documentation-2823595-7.patch | 2.59 KB | mfernea |
Comments
Comment #2
Anonymous (not verified) commentedJust want to second that.
Please make the extra effort to explain your nice contribution. This is a problem for many modules in Drupal and it is very contra productive for Drupal. I am a "late beginner" with Drupal and I get the impression that it "should" be hard to learn Drupal.
Comment #3
mohc commentedThis module would be so useful if we had a clue how to use it. Just one page of documentation would make all the difference, please.
Comment #4
morten-h commentedJust wanted to support this suggestion.
Better documentation would be/have been really nice.
An few examples of how it's used would make all the difference.
Comment #5
mfernea commentedFirst step would be to create Classy paragraphs styles.
Go to Structure / Classy paragraphs style and click on "Add Classy paragraphs style" and configure the new style.
Second step is to add a new field to reference the style just created. This can be done by editting a paragraph type and add a new "Reference" field (select Other...). In the next page select Configuration / Classy paragraphs style.
This would be a first draft. If we agree upon the content I will create a new patch to update the README.txt file within the module.
Comment #6
brandonratz commentedHere is a more complete README.txt draft using markdown which builds on your D7 documentation comments and @mfernea comment.
Comment #7
mfernea commentedAs per https://www.drupal.org/docs/develop/documenting-your-project/module-docu... the README file can be an md file, so I changed the file extension. There it says that the Overview should match the one on the module's page, so I used that one.
I used https://www.drupal.org/node/2181737 as a model. I merged the texts from the module's page and from #6 and added more sections.
Comments and suggestions are welcomed. :)
Comment #8
mfernea commentedComment #9
bdanin commentedThis is much better, the patch applied cleanly and helped a great deal, thank you.
Comment #10
mfernea commented@bdanin: Maybe it's best then to mark it as RTBC :).
Comment #11
bdanin commentedComment #12
i-trokhanenkoComment #13
i-trokhanenko+1 RTBC
Comment #15
i-trokhanenkoThanks!
Comment #17
rex.barkdoll commentedThis might not get seen, but I'm going to add to the instructions for others that end up finding this. I'd really like to see the Drupal Community putting out more guides with this level of granularity and ideally with screenshots.
Here's my workflow:
composer require drupal/classy_paragraphsdrush pm:enable classy_paragraphs{{ attributes.addClass(classes) }}as part of it. This variable is what's going to pick up the Classy Paragraphs classes, so if you've removed it or hidden it in your file, you may need to do some work to add it back in. It cannot be included in the lines:{% block paragraph %}or{% block content %}. It has to be on an HTML element.drush crThis is a rough example of a paragraph's twig file:
PLEASE verify with what TWIG is showing on your site. This one may be different than your site.
Final Note:
After adding new Styles in the Classy Paragraphs Config page, clear your cache for them to become available on the front end.
Comment #18
cbeem commented#17 did it for me. Thank you very much! This was impenetrable otherwise.
Comment #19
ressaThanks for documenting the configuration of the module @rex.barkdoll, it's very helpful.
I have created a Merge Request for the project
README.mdbased on your detailed documentation in #3268322: Add more detailed documentation. You can preview it at https://git.drupalcode.org/project/classy_paragraphs/-/blob/10b7efe774e1....