Include PHP code directly in MetaMod

(9 votes, average 4.00 out of 5)

A MetaMod can be used as a general purpose PHP module, because any text that you output from the module will appear in the module position. This recipe shows you how.

Hey, MetaMod PHP is just normal PHP, so you can put anything you like in here!

This includes “echo” commands or anything else that produces output.

Any PHP output is output after any “Quick module id include” modules, but before any modules that you “return” from the PHP. It can be really handy to use MetaMod just as a generic PHP/HTML module, with the added benefit of being able to include extra modules if necessary.

if ($user->name == "John Doe") echo "Hi John, nice to see you!";
else if ($user->usertype != "" && $user->usertype != "Public Frontend") {
  echo "Please log in!";
else echo "Welcome " . $user->usertype;