Pregunta

I'm trying to write a conditional statement in a template file to check if the value of a 'node reference' field is not equal to a certain value. This is what I have so far:

<?php
$value = ( $content['field_collection_or_bespoke']['#items']['0']['value'] );

if ( $value != 'bespoke' ) : ?>

    // Do something if not bespoke 

<?php endif ?>

At the moment it is always evaluating to true. I'm not sure if $value is not getting the correct field or that the value I'm testing against is wrong. If that's the case how can I find the values of the field_collection_or_bespoke field?

Many thanks

¿Fue útil?

Solución

Problem is probably in the incorrect reference:

$value = ( $content['field_collection_or_bespoke']['#items']['0']['value'] );

Language key is missing in the array.

It should be something like:

$value = ( $content['field_collection_or_bespoke']['und']['0']['value'] );

Please do Print_r($content['field_collection_or_bespoke']); to get details.

Otros consejos

If Its a Theme file or function try print the variable passed the theme file or function

using *replace $var with your variable name.always use strcmp() for comparing string values

echo "<pre>"
print($var);
die;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top