I am using the following to print a location:

print theme ('location', $location);

However, I need it to print 'No location entered' if not location is entered. Does anyone know how to do this with PHP?

Comments

shakethetv’s picture

if($location!=""){
print theme ('location', $location);  }else{
echo"No location entered.";
}

shakethetv.com - lyrics - music

masande’s picture

shakethetv's code is perfectly workable but can be shortened slightly...

<?php

if ($location) {
  print theme('location', $location);
} else {
  print 'No location entered.';
}

?>

Mark Sanders
Q Collective

Mark Sanders
Q Collective

gpk’s picture

print $location ? theme('location', $location) : 'No location entered';

gpk
----
www.alexoria.co.uk

shakethetv’s picture

ty i did not knew this one

storbaek’s picture

Not sure what "ternary operator" is, but it works perfectly. Thanks!

gpk’s picture

expr1 ? expr2 : expr2

means

if expr1 then expr 2 otherwise expr3

gpk
----
www.alexoria.co.uk

traxer’s picture

'No location entered' looks like a string that should be translated:
print $location ? theme('location', $location) : t('No location entered');

--
~/.singatrue: file not found

basicmagic.net’s picture

subscribe

Drupal samurai for hire, based in Buffalo, New York, USA.
15+ years Drupal, 20+ years web.
http://basicmagic.net

droople’s picture

link