Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save deckchairhq/290593 to your computer and use it in GitHub Desktop.
Save deckchairhq/290593 to your computer and use it in GitHub Desktop.
CakePHP helper for InlineJS (Facebook FBML Tab Page Requirement)
<?php
class InlinejsHelper extends AppHelper {
var $jsSubFolder = 'fbml';
function renderGeneric() {
$genericScript = 'fbmlgeneric.js';
$genericjs = new File(JS . $this->jsSubFolder . DS . $genericScript);
$output = '// - Generic Scripts:' . "\n";
$output .= $genericjs->read();
return $this->output( $output );
}
function renderSpecific($viewName) {
$specificjs = new Folder(JS . $this->jsSubFolder . DS . $viewName . DS);
list($folders, $files) = $specificjs->read();
$output = '// - Specific Scripts:' . "\n";
foreach ($files as $file) {
$jscode = new File($specificjs->path . $file);
$output .= '// -- Script: ' . $viewName . DS . $file . "\n";
$output .= $jscode->read() . "\n";
}
return $this->output( $output );
}
}
?>
!! Usage In View !!
<script>
<!--
<?php echo $inlinejs->renderGeneric(); ?>
<?php echo $inlinejs->renderSpecific(); ?>
//-->
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment