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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sadashiv’s picture

Try 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.

doors’s picture

Thanks 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.


if ($row->type == 'Product'){
     print($row->title);
     print($row->nothing);
     print ("Yow waah gwaan");
     print($row->type);
}
else {
     
     print($row->nothing_1);
     print ("Mi deh yah");
     print($row->type);
}

sadashiv’s picture

Is $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.

doors’s picture

All 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.

MustangGB’s picture

Issue summary: View changes
Status: Active » Closed (outdated)