Skip to main content
replaced http://drupal.stackexchange.com/ with https://drupal.stackexchange.com/
Source Link

I've got a field collection with has a div wrapper with the classes "field-collection-container clearfix" I'd like to add an additional class to this div. How would I go about this?

I've tried this:

MYTHEME_preprocess_field(&$variables, $hook){ if($element['#field_name'] == "FIELD_COLLECTION_NAME"){ $variables["element"]["#prefix"] = '<div class="field-collection-container clearfix MY_CLASS">' } } 

But this doesn't seem to have any affect. I'm not sure what else to try, I also found an answer here http://drupal.stackexchange.com/a/142389/39899https://drupal.stackexchange.com/a/142389/39899 but that doesn't seem to do anything either. The code I put above actually runs as I did a var_dump() and saw the results but when I tried that with the answer I linked to I got nothing.

[UPDATE]

Just to clarify, I'm looking specifically to amend the div with the class "field-collection-container" not add another wrapper. The reason being that I think it's just tidier to make use of the markup Drupal already outputs rather than just adding more do it.

I've got a field collection with has a div wrapper with the classes "field-collection-container clearfix" I'd like to add an additional class to this div. How would I go about this?

I've tried this:

MYTHEME_preprocess_field(&$variables, $hook){ if($element['#field_name'] == "FIELD_COLLECTION_NAME"){ $variables["element"]["#prefix"] = '<div class="field-collection-container clearfix MY_CLASS">' } } 

But this doesn't seem to have any affect. I'm not sure what else to try, I also found an answer here http://drupal.stackexchange.com/a/142389/39899 but that doesn't seem to do anything either. The code I put above actually runs as I did a var_dump() and saw the results but when I tried that with the answer I linked to I got nothing.

[UPDATE]

Just to clarify, I'm looking specifically to amend the div with the class "field-collection-container" not add another wrapper. The reason being that I think it's just tidier to make use of the markup Drupal already outputs rather than just adding more do it.

I've got a field collection with has a div wrapper with the classes "field-collection-container clearfix" I'd like to add an additional class to this div. How would I go about this?

I've tried this:

MYTHEME_preprocess_field(&$variables, $hook){ if($element['#field_name'] == "FIELD_COLLECTION_NAME"){ $variables["element"]["#prefix"] = '<div class="field-collection-container clearfix MY_CLASS">' } } 

But this doesn't seem to have any affect. I'm not sure what else to try, I also found an answer here https://drupal.stackexchange.com/a/142389/39899 but that doesn't seem to do anything either. The code I put above actually runs as I did a var_dump() and saw the results but when I tried that with the answer I linked to I got nothing.

[UPDATE]

Just to clarify, I'm looking specifically to amend the div with the class "field-collection-container" not add another wrapper. The reason being that I think it's just tidier to make use of the markup Drupal already outputs rather than just adding more do it.

added 294 characters in body
Source Link
Neil Nand
  • 306
  • 2
  • 15

I've got a field collection with has a div wrapper with the classes "field-collection-container clearfix" I'd like to add an additional class to this div. How would I go about this?

I've tried this:

MYTHEME_preprocess_field(&$variables, $hook){ if($element['#field_name'] == "FIELD_COLLECTION_NAME"FIELD_COLLECTION_NAME"){ $variables["element"]["#prefix"] = '<div class="field-collection-container clearfix MY_CLASS">' } } 

But this doesn't seem to have any affect. I'm not sure what else to try, I also found an answer here http://drupal.stackexchange.com/a/142389/39899 but that doesn't seem to do anything either. The code I put above actually runs as I did a var_dump() and saw the results but when I tried that with the answer I linked to I got nothing.

[UPDATE]

Just to clarify, I'm looking specifically to amend the div with the class "field-collection-container" not add another wrapper. The reason being that I think it's just tidier to make use of the markup Drupal already outputs rather than just adding more do it.

I've got a field collection with has a div wrapper with the classes "field-collection-container clearfix" I'd like to add an additional class to this div. How would I go about this?

I've tried this:

MYTHEME_preprocess_field(){ if($element['#field_name'] == "FIELD_COLLECTION_NAME){ $variables["element"]["#prefix"] = '<div class="field-collection-container clearfix MY_CLASS">' } } 

But this doesn't seem to have any affect. I'm not sure what else to try, I also found an answer here http://drupal.stackexchange.com/a/142389/39899 but that doesn't seem to do anything either. The code I put above actually runs as I did a var_dump() and saw the results but when I tried that with the answer I linked to I got nothing.

I've got a field collection with has a div wrapper with the classes "field-collection-container clearfix" I'd like to add an additional class to this div. How would I go about this?

I've tried this:

MYTHEME_preprocess_field(&$variables, $hook){ if($element['#field_name'] == "FIELD_COLLECTION_NAME"){ $variables["element"]["#prefix"] = '<div class="field-collection-container clearfix MY_CLASS">' } } 

But this doesn't seem to have any affect. I'm not sure what else to try, I also found an answer here http://drupal.stackexchange.com/a/142389/39899 but that doesn't seem to do anything either. The code I put above actually runs as I did a var_dump() and saw the results but when I tried that with the answer I linked to I got nothing.

[UPDATE]

Just to clarify, I'm looking specifically to amend the div with the class "field-collection-container" not add another wrapper. The reason being that I think it's just tidier to make use of the markup Drupal already outputs rather than just adding more do it.

Source Link
Neil Nand
  • 306
  • 2
  • 15

Add class to field collection wrapper

I've got a field collection with has a div wrapper with the classes "field-collection-container clearfix" I'd like to add an additional class to this div. How would I go about this?

I've tried this:

MYTHEME_preprocess_field(){ if($element['#field_name'] == "FIELD_COLLECTION_NAME){ $variables["element"]["#prefix"] = '<div class="field-collection-container clearfix MY_CLASS">' } } 

But this doesn't seem to have any affect. I'm not sure what else to try, I also found an answer here http://drupal.stackexchange.com/a/142389/39899 but that doesn't seem to do anything either. The code I put above actually runs as I did a var_dump() and saw the results but when I tried that with the answer I linked to I got nothing.