[support] Adding PHP code/complex content to a node

DTH david at hartster.org
Mon Jan 30 16:30:28 UTC 2012


Our D7 site is a mixture of nodes and custom pages created via
hook_menu. However, there's some pages where we want to take advantage
of them being nodes (revision info, translatable, copy editable by
normal users), which also including custom php code and complex forms
etc.

For fairly obvious reasons I don't want to do <?php
include("file.php") ?> etc in the node content.

I'm currently doing things like

function david_node_view($node, $view_mode, $langcode) {
	if ($node->nid==2){
	//Some complex content generated some way such as
        $file = file_get_contents('file.php', true);
	$node->content['extra'] = array(
	    '#markup' => $contents,
	    '#weight' => 10
		 );
	}
}

which works fine and everything. It's fairly scalable although relying
on nid (and tnid etc) is a bit of a pain. I'm just wondering if
there's a better solution I'm missing.


More information about the support mailing list