I am having a custom hand coded PHP page within a Drupal module that loads in a fancybox. I want the Drupal t() function to work in it. What should I include in the file to make it function?

  • Are you including the PHP file from a module? – kiamlaluno Oct 16 '12 at 8:26

Include these lines in your php file

define('DRUPAL_ROOT', getcwd());

include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  • If the page is loaded from a module, I would imagine that Drupal is already bootstrapped, surely? – Chapabu Oct 16 '12 at 8:29
  • 1
    I guess that depends on how he includes the file. His question is a bit vague about how that is handled. If he, for example, has a php file as a POST callback and the file just happens to be in the module directory, then it wouldn't get any Drupal functionality at all. – hampusn Oct 16 '12 at 9:15
  • @hampusn This is what esafwan asked. – Mathankumar Oct 16 '12 at 9:20
  • @Mathankumar The question doesn't actually state if the file is loaded through Drupal or just with a standard require/include call. – hampusn Oct 16 '12 at 10:05

By default the t() function is accessible from any custom module.

You shouldn't have to include any other files/code.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.