Hi,

This will be a cool snippet once it works.

I would like, whenever an album reference is present in my news node, to display a camera icon in the teaser.

I have a news node with a field named field_album_link which is a node reference to an album id, and a computed field which will hold an image name if an album is linked.

Here is what I have tested successfully:

Computed code:

$node_field[0]['value'] = 'cameracanonicon.jpg';

Display format:

$display = '<img src="files/images/' . $node_field_item['value'] . '">';

The above code successfully displays the camera icon in the teaser of the news node.
Now, the code will only be useful if I can add a condition like "if the album reference field is not empty, do.."

I have tried the if statement with !='', !='0', !=null, ! is_null(), but the if statement never seems to work.
I did re-save my node with an empty album reference, but the camera icon persists.

Can someone please help me fix the code below?

Computed code:

if ($node->field_album_link[0]['value'] != '') $node_field[0]['value'] = 'cameracanonicon.jpg';

Display format:

$display = '<img src="files/images/' . $node_field_item['value'] . '">';

Thanks,
ktnk

Comments

ktnk’s picture

Title: Cool Snippet to display icons » Cool Snippet to display icons - needs one last bit of php

I tried the following IF statement,
Still doesn't work.
if (!empty($node->field_album_link[0]['view']))
Any suggestions?

ktnk’s picture

Status: Active » Closed (fixed)

Found it!!

if (content_format('field_album_link', $node->field_album_link[0]) > '') $node_field[0]['value'] = 'cameracanonicon.jpg';

based on: http://drupal.org/node/62485