3.x Using Eval

From Fabrik

Jump to: navigation, search

Introduction

Eval is used throughout Fabrik and is very cool.  

You can learn more about what Eval is at the Fabrik Glossary but basically, in the contect of Fabrik, when you see a text area with a checkbox near it that says Eval and you check that checkbox, it is going to interpret whatever you put in that text area as PHP.  

Syntax

When using Eval in Fabrik you should:

  • never start or end your PHP code with <?php and ?>
  • always return a string as the last line of your PHP code

Where Is Eval Used?

You can use Eval in:

  • element (plugin type: display) > options > default
example code:
$user = JFactory::getUser();
$name = $user->get('name');
return $name;

this will output the user's name as the label.

  • element (plugin type: field) > publishing > tips > tip text

example code:

$user = JFactory::getUser();
$name = $user->get('name');
$userid = $user->get('id');
$email = $user->get('email');
return 'this is so cool, the logged in user\'s name is ' . $name . ', their id is ' . $userid . ' and their email is ' . $email . '.';

this will output:

this is so cool, the logged in user's name is [username], their id is [userid] and their email is [useremail].

Personal tools