I'm doing some PHP code examples for a class in a fancy Drupal site.
I have a "Code" content type.
I have a "field_php" that gets processed on the actual node.
I have a view that uses "node/%/code" to display the code formatted via Geshi:
- View PHP Body: Link back to node/1
View PHP footer: PHP code to pull geshi formatted "field_php"
<?php include_once('sites/all/libraries/geshi/geshi.php'); $page = $view->args[0]; $node = menu_get_item("node/$page"); $source = $node['page_arguments'][0]->field_php['und'][0]['value']; $language = 'php'; $geshi = new GeSHi($source, $language); echo $geshi->parse_code(); ?>
LASTLY I have a node--code.tpl.php edited to include a "View Code" link at the top of each "code" page. The include_once/echo at the top is the following:
<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<?php
include_once('sites/wernercd.php/public/~functions.php');
echo "<a href=\"" . curPageURL() . "/code\">Code For You!</a>";
?>
<?php if (!$label_hidden) : ?>
<div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:
</div>
<?php endif; ?>
<div class="field-items"<?php print $content_attributes; ?>>
<div class="field-item even"<?php print $item_attributes[0]; ?>><?php print render($items[0]); ?></div>
</div>
</div>
I don't know why, but I feel like I'm doing it wrong. It works like I want it, but I just feel like its the "wrong" way to go about doing it.
What would the "recommended" way of getting this desired output be? How could I change this to catch issues unforseen by my naivete?