1

I'm trying to modify all fields output for a specific content-type called Netrunner-Card.

After digging through Stack Exchange I ran across someone that suggested using:

function theme_field__content_type()

But it isn't working. My implementation is:

function blinks_responsive_field__netrunner_card($variables)
{
    $output = 'TEST';
    return $output;
}

Which if I understand correctly, this should remove all field data for a content type of 'Netrunner Card' but it doesn't.

I have multiple fields for each card. There are also card types which I want to output differently, (i.e. An Operation card should look like this, an Identity card should look like this, etc.). So I want to use a switch function (PHP) to check the card types and adjust fields as needed. First I have to get access to the fields and I'm trying to do this inside of ONE function versus a separate function for each field which would add a lot of duplication.

My theme is called blinks_responsive. My content type is netrunner_card. I am out of ideas.

UPDATE: I don't know if it matters but I discovered that I had a field.tpl.php file in my theme templates folder. Wondering if that caused me issues. Still not working tho.

  • Define "not working". Function is never called? Or it is called but seems to do nothing? – Mołot May 17 '13 at 7:06
  • Common mistakes: 1 - Take a look to database to confirm that netrunner_card is the machine name of this content type. 2 - Clear the cache 3 - Are you returning the output? – Rufein May 17 '13 at 11:55
1

The problem lies in having other functions that alter OTHER fields of the SAME content type.

Earlier in my development, I created two functions, one each, for two specific fields. Even though my adjustments for those fields were minor (added classes to one and added an img tag to another) it still caused the generic function to fail.

Because I had those other functions...

theme_field__field_name__content_type

It made the generic function for all fields...

theme_field__content_type

...not work.

Once I removed those other functions? Suddenly theme_field__content_type started working instantly.

0

You can theme fields with both a template, and in a function. In 99.9% of cases, when a theming function 'does not work', it's because it has a wrong name. So is in your case. Your function has a theme name + the content type name. It lacks the actual field name. To pair up hierarchy of field (content type > field name), you should use templates.

Take an existing field.tpl.php, rename it as per templating suggestions (http://drupal.org/node/1089656), and edit as required.

You can alternatively preprocess a field (http://api.drupal.org/api/drupal/modules!field!field.module/function/template_preprocess_field/7), depending on what you want to do.

  • The order of hook_suggestions make by default: 1 field--field-name--content-type.tpl.php 2 field--content-type.tpl.php 3 field--field-name.tpl.php 4 field--field-type.tpl.php . It's also possible the way ramdomblink has proposed. – Rufein May 17 '13 at 11:44
  • 'Not Working' What I mean by this is... I have taken that function: function blinks_responsive_field__netrunner_card($variables) And as a test, I have that function doing this: $output = 'TEST!'; return $output; Which, if I understand correctly, should remove all data that is pumped into the fields for the card... and output should be a blank page. But it isn't... Am I testing this wrong? – randomblink May 17 '13 at 12:46
  • Alexei: The reason I am not going with your suggestion is that I am REALLY trying to maintain MVC on this project. And all functionality should be in the template.php file and all markup should go in the tpl.php. So whereas I could theoretically use a field--netrunner-card.tpl.php I would have to do a bunch of logic on the tpl file and that should be reserved for template.php instead. – randomblink May 17 '13 at 13:42
  • 1
    @randomblink Bit of friendly advice - don't try to make Drupal conform to MVC (I've done so myself several times and failed miserably). It's fiercely AOP and the paradigms within just don't translate to MVC. Save yourself the headache and just do what Drupal wants you to do :) – Clive May 17 '13 at 13:58
  • Ok... not familiar with AOP, I'll have to look it up and see what that means. (Aspect-oriented Programming) But in this instance, it just makes sense to keep the logic in the template.php and the markup in tpl.php, but thank you. – randomblink May 17 '13 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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