How to Alter Views Result in Drupal 7 i've several list of products display on a Drupal block. I get the list of products using views module. Then, i've several pages dedicated for each product. Before the list of products display on a block, i need to check if the page for the product exist of not. if exist, i need to display the product as list, but if not exist, i don't want to display it as link.

Example:

I have pages:

Product/A for product A

Product/C for product C

I have products:

A

B

C

D

So, views result that display on the block, should be:

A -> as link

B -> not a link

C -> as link

D -> not a link

How can I achieve that?
The only way I can think is to use a views field template file to be overridden.   

Copy the template sites/all/modules/views/theme/views-view-field.tpl.php to your current enabled theme folder. Assuming that you have a block view "product-listing", you could rename it to views-view-field--product-listing--block.tpl.php.

Rescan template files in your view theming information. The file views-view-field--product-listing--block.tpl.php just created should be highlighted with bold. Now, you have an active custom field template for your block view.


Then, you can edit the template as you need. Here is a sample code:  

&lt;?php
 $alias = drupal_get_path_alias('node/'.$row-&gt;nid);
 if(drupal_valid_path($alias)){
     $url = url($alias);
?&gt;
    &lt;a href="&lt;?php print $url; ?&gt;"&gt;&lt;?php print $row-&gt;node_title; ?&gt;&lt;/a&gt;
&lt;?php
}else{
?&gt;
    &lt;span&gt;&lt;?php print $row-&gt;node_title; ?&gt;&lt;/span&gt;
&lt;?php
}


You can check if a page ( or path ) exists or not by using drupal_valid_path().