[support] Best way to include complex PHP in nodes/pages

DTH david at hartster.org
Tue Apr 12 09:51:43 UTC 2011


We're converting a multidomain, multilanguage site over to Drupal 6.
We have a number of existing pages that make heavy use of PHP (while
some of these could (with work) be converted over to use things like
Feeds + Views + CCK, some can't, plus the code already exists).

What's the easiest way to include these scripts, assuming that they
may want to live in different menus in different languages, and that
we want these pages to also work like other pages on our site (e.g. to
be able to flag translations as out of date, use Rules to send emails
when flagged, show up in Views etc).

[And we want things like the code under source control]

Using hook_menu to create a MENU_CALLBACK seems to mean we couldn't
treat them like other pages (have translators easily edit titles/content, use
Views/Rules etc) - it also seems to require some work to have the menu
path itself be translated (without creating multiple versions)

Using hook_nodeapi to add the PHP to the node only works if it is
always at the end (or beginning) of any content (so a page like
[french intro]$PHP_CODE[french outro] wouldn't work).

Using the PHP filter to include a file works, but means I'd need to
give translators the right to use PHP, which isn't a complete no-no
(they're all employees at least) but is something I obviously want to
avoid if possible.

The best solution I've come up with so far is creating a custom filter
that replaces a keyword/token with a file/function so
translators/editors would add {{ZIP_LOCATOR_SCRIPT}} to their page and
the relevant code would get included.

Is this overthinking it? Is there a better way?


More information about the support mailing list