Drupal: How to Check Snippet Working
If PHP-snippet has an error the whole website could be unavailable. Therefore, before saving a block/page you should make sure that snippet works correctly.
Solution:
- Create a file in your site root (for example, test.php)
- Insert code of php-snippet and two additional lines before to this file:
<?php
include_once ‘./includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// snippet code
?> - To check this, enter to your web-browser: http://example.com/test.php (where test.php is name of the file)
Notes:
- Your snippet should output some info to browser. Otherwise block with this snippet won’t be shown on a page.
- Do not forget to remove this file after verification.
Actually, it looks like you need to define DRUPAL_ROOT if you are using Drupal 7.
It should looks something like this:
Wow. That totally failed.
<?php
define(‘DRUPAL_ROOT’, ‘/home/ubuntu/repository/web’);
include_once ‘./includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// snippet code
echo “hello”;
?>