0

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?

3

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.

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

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

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.