I'm working on an old Drupal 7 site.

In the template file paragraphs-item--user-block-paragraph.tpl.php the content is being rendered, but the class is not added to the element.

Here is the code:

$content['#attributes']['class'][] = 'my-class';
print "<script>alert('".$content['#attributes']['class'][0]."');</script>"; // confirmed variable is set to my-class
print render($content); // confirmed correct file name

What variable in $content determines the classes of the element?

1 Answer 1


I don't know the structure of the template but it should be something like this:

$content['field'][0]['#attributes']['class'][] = 'my-class';


$content['field']['#attributes']['class'][] = 'your-class';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.