Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By DrupalDope on
Using Drupal's PHP module, it is possible to build a page within the Drupal system and that works roughly as follows:
URI: domain/node/1
page structure:
drupal includes
drupal page elements before node
<my php code>
drupal page elements after node
The above sort of wraps the node containing the PHP code into Drupal.
What I would like to achieve is exactly the opposite: wrap Drupal with PHP:
URI: domain/directory1/file.php
page structure:
/*get to Drupal root*/
chdir("../");
ob_start();
include(drupalpage); //something that outputs a Drupal page with a dummy node prepared to contain markers so the resulting HTML can be split into header and footer to wrap the php code that follows
$drupalpage = ob_get_clean();
ob_end_clean();
// using the dummy node contents, split drupalpage into header and footer
$drupalheader=substr($drupalpage, 0, until node);
$drupalfooter=substr($drupalpage, from node, until end);
// get into the directory where our PHP system is
chdir("directory1/");
<do whatever our templated PHP system wants to do>
// wrap our PHP system output in drupalheader and drupalfooter
// for example:
$template->assign_vars(array('HEADER' => $drupalheader,'FOOTER' => $drupalfooter));
<output page from PHP system>
What URI should I use as include(drupalpage) to get the proper HTML output of the page?
Thank you for your help
Comments
got it myself, yeehah!
I'm so happy I figured it out myself :-)
first, the name of the php file that is used has to be added in .htaccess to the list of files to which direct access is allowed from HTTP
then, since include doesn't allow arguments, we can set the q variable in the GET array and then do the include:
that does the trick ;-)
the rest is straightforward