0

The following PHP in a node tpl file:

check_plain($node->field_room[$node->language][0]['value']) 

Will print this in the page: Value1

What I want however is if the field has a value of 'Value1' then I want to print something else on the page. Ive tried the following but I think I have a syntax error:

if ( check_plain($node->field_room[$node->language][0]['value']) == "Value1" ) { echo "<p>Print something else </p>"; } 
1
  • You should not need the check_plain() call for this purpose, by the way. I don't think it's the cause of the problem, though, unless the value you are actually checking for has HTML special characters in it. Commented Mar 19, 2013 at 17:01

1 Answer 1

2

There's no syntax error in the second code sample, if you're getting a syntax error it's not coming from those lines.

The best way to get values from an entity is with field_get_items():

$items = field_get_items('node', $node, 'field_room'); if (count($items) && check_plain($items[0]['value']) == 'Value1') { // Do something } 

But unless you have some sort of multi-lingual issue the code you've got should do exactly the same thing as that, so the problem might be elsewhere.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.