0

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?

1
  • Are you including the PHP file from a module?
    – apaderno
    Oct 16, 2012 at 8:26

2 Answers 2

2

Include these lines in your php file

define('DRUPAL_ROOT', getcwd());

include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
4
  • If the page is loaded from a module, I would imagine that Drupal is already bootstrapped, surely?
    – Chapabu
    Oct 16, 2012 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, 2012 at 9:15
  • @hampusn This is what esafwan asked. Oct 16, 2012 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, 2012 at 10:05
0

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 and acknowledge you have read our privacy policy.

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