0

I have a few content types on my Drupal instance. Eg. case study, forum topic etc.

I have built a view, to display few nodes and their content types.

In this view, I want to display the content type as case studies instead of case study, forum topics instead of forum topic.

I don't want to change the content type globally, but I want to change the content type only in this view.

Is there any hook that I can write to make this change?

1 Answer 1

1

Add a field to each of your content types, let's call it "Nickname" and enter the value you want to appear in your view, ie for Case Study enter "Case Studies". Now add Nickname to your View fields, and it should output the right text for each content type.

4
  • Thanks for the response. Your solution will work, but I have about 10 different content types and we may add more content types in the future. Every time we add a content type, we need to add an extra field to that content type even if we don't want to change the name of the content type. Oct 19, 2015 at 16:50
  • 1
    The other way to do it automatically (but you will have to figure out how to do it language-wise) is to rewrite in your View the output of your content type. So from your View click on the content type field, then select Rewrite Results, then check "Rewrite the output of this field", and under the text box you will see Replacement Patterns, click on it and you'll see the available tokens you can use in your text box. My guess is you will need to do something like this [type]s in your text box. Oct 19, 2015 at 17:02
  • I am currently rewriting my view using tokens. But [type] displays Case Study as Case Study. Can I use conditional tags? So that, if([type] == 'Case Study') I'd print Case Studies instead. Oct 20, 2015 at 5:31
  • Using PHP in your view rewrite is discouraged, see this post . Instead, use computed field module or create a template for your view, and use your php logic in this template to rewrite your field output. Check out one [tutorial] (wdtutorials.com/…) there are many more if you google drupal "views template tutorial" Oct 21, 2015 at 14:29

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.