I made a custom template for my view to print fields into a custom html syntax. The problem I have is that in the view I am calling all content types. Now, in my template file I want to display certain information depending on what content type the content is coming from.

For instance, I want something like this:

If (node->type['animals']{
    print 'this is the animal node';
    print 'this is not the animal node';

My fields inside the view are printed as follows, but this works:

<?php print $fields['title']->content; ?>

The only problem I am having is calling the node type.

I tried adding content type to my views in drupal, then tried it that way:

<?php if ($fields['type']->content = 'animals'){} ?>

but the view looks through the document and see that there is a content type with that name, and prints the data anyway.

  • is the view template for the entire view, or for a single row? if it's for the entire view, and you include multiple content types, I don't think there's much you can do about it. You may want to look at both a template for the view, and a separate one for the rows
    – Geoff
    Commented May 3, 2015 at 18:21
  • Entire view. All I want to do is change a label for a specific title. I also followed these steps exactly: stackoverflow.com/questions/11459700/… but it prints an empty string. Commented May 3, 2015 at 19:10
  • and that example uses: views-view-fields--xxx--xxx.tpl.php which applies to each field, not to the entire view. I think you're using the wrong template
    – Geoff
    Commented May 3, 2015 at 19:13

1 Answer 1


I believe you are using the wrong template in order to access the relevant information. As your comment states your view template is for the entire View, and as you say it looks through the entire document and will always find the content type if any content of that type is present.

Since you are trying to affect a single field, you should look at other template suggestions for fields only in order to process the fields individually instead of trying to do it at the whole View stage.

  • I got it working, If i do an If statement checking my string length, and make it smaller than x, it works. So I think the '$fields['type']->content' value is not correct. Commented May 3, 2015 at 19:27

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.