Skip to content

Instantly share code, notes, and snippets.

@AlexTiTanium
Created January 9, 2013 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexTiTanium/4497294 to your computer and use it in GitHub Desktop.
Save AlexTiTanium/4497294 to your computer and use it in GitHub Desktop.
<?php
namespace lib\Templates\EngineExtensions;
use Twig_Extension;
use lib\Core\IncluderService;
use Twig_Function_Method;
class ViewHelper extends Twig_Extension {
/**
* @return array
*/
public function getFunctions(){
return array(
'addCss' => new Twig_Function_Method($this, 'addCss',array('is_safe' => array('html'))),
'addJs' => new Twig_Function_Method($this, 'addJs',array('is_safe' => array('html')))
);
}
/**
* @param $path
*
* @return string
*/
public function addCss($path){
if(is_array($path)){
$pathArray = array();
foreach($path as $itemPath){
$pathArray[] = $this->addCss($itemPath);
}
return implode("\n", $pathArray);
}
return IncluderService::$skin->css($path);
}
/**
* @param $path
*
* @return string
*/
public function addJs($path){
if(is_array($path)){
$pathArray = array();
foreach($path as $itemPath){
$pathArray[] = $this->addJs($itemPath);
}
return implode("\n", $pathArray);
}
return IncluderService::$skin->js($path);
}
/**
* ViewHelper::getName()
*
* @return string
*/
public function getName(){
return 'ViewHelper';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment