3

I have an automatically generated title of an address with an if empty statement in the middle of the other tokens:

[node:field_street], [node:field_number],
<?php
$floor= '[node:field_floor]';
$ground = '[node:field_ground_floor]';
if (empty($floor)) { return $ground; }
else
{ return ' Floor '.$floor; };
?>,
[node:field_location_address:postal_code], [node:field_location_address:city]

but the token after the php statement is not displayed. If I put the php statement at the end after all other tokens, everything is displayed. What am I doing wrong?

2

I tried your snippet and could reproduce the problem. What worked for me was printing/echoing instead of returning.

My code that reproduced the error:

[current-user:name]
,
<?php
$floor= '[node:nid]';
$ground = '[node:created]';
if (empty($floor)) { return $ground; }
else { return " Floor floor"; }
?>,
[current-page:url]

produced the title "admin, Floor 228".

My updated code (echo instead of return) worked:

[current-user:name]
,
<?php
$floor= '[node:nid]';
$ground = '[node:created]';
if (empty($floor)) { echo $ground; }
else { echo " Floor $floor"; }
?>,
[current-page:url]

and produced the title "admin, Floor 228,http://localhost/drupal/node/228/edit"

Verdict: I believe this is expected behaviour following from the use of return; it exits the current code block, and therefore the rest of the code is never executed.

Hope this helps!

2
  • Thank you, @Stefanos, I confirm it works like a charm :) – user48533 Mar 5 '16 at 11:57
  • You're welcome, was a great question, had to think about this through! – Stefanos Petrakis Mar 5 '16 at 12:00

Your Answer

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