Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I have been trying to figure this out the entire weekend but can't find documentation to help.
I have a view that displays two content types for search results. Now these two content types have different fields and I have opted to override the them template file views-view-fields.tpl. I want to display certain fields based on the content type of the fields being shown.
Can someone please help?
Comment | File | Size | Author |
---|---|---|---|
#2 | 1353961824855-uploadscreenshot-dot-com.png | 222.01 KB | doors |
#2 | 1353961901021-uploadscreenshot-dot-com.png | 62.89 KB | doors |
Comments
Comment #1
sadashiv CreditAttribution: sadashiv commentedTry http://drupal.org/project/views_php which will allow you to execute php code. You can add the field from the content type and exclude them from dispaly. Then add a Global php field and check the necessary conditions and then echo the field depending on the condition using $row->field_name.
Hth,
Sadashiv.
Comment #2
doors CreditAttribution: doors commentedThanks for the quick reply.
I just tried your solution but the fields are not showing.
I am generating a view based on Search API and Apache Solr, so the type of view is my Node Index created within Search API.
My PHP code is as follows. It only prints the "Mi deh yah" string in the else statement.
Please see attachment for view images.
Comment #3
sadashiv CreditAttribution: sadashiv commentedIs $row->type variable available in the "Available Variables" list of views php. If it is not present then please add the type as field in the views result and exclude it from display if you don't want it to be shown in the results to the user.
Hth,
Sadashiv.
Comment #4
doors CreditAttribution: doors commentedAll the variable used were listed as available variables and all the $row variables are empty.
I had added the content type field and you can see it from the screenshot.
Comment #5
MustangGB CreditAttribution: MustangGB commented