Created
May 20, 2015 12:44
-
-
Save cedricziel/3aef53926e1f4d579273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace CedricZiel\Lister\ViewHelpers\Angular; | |
/** | |
* This is free software; you can redistribute it and/or modify it under | |
* the terms of the GNU General Public License, either version 2 | |
* of the License, or any later version. | |
* | |
* For the full copyright and license information, please read the | |
* LICENSE.txt file that was distributed with this source code. | |
* | |
* Usage: <i:angular.inlineTemplate | |
* path="{f:uri.resource(extensionName: 'lister', path: 'App/TableList/src/templates/directives/simple-pane/simple-pane-title.html')}" | |
* id="directives/simple-pane/simple-pane-title.html"/> | |
* | |
* The TYPO3 project - inspiring people to share! | |
*/ | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; | |
/** | |
* Class InlineTemplateViewHelper | |
* @package CedricZiel\Lister\ViewHelpers\Angular | |
*/ | |
class InlineTemplateViewHelper extends AbstractTagBasedViewHelper { | |
/** | |
* @var string | |
*/ | |
protected $tagName = 'script'; | |
/** | |
* Initialize | |
* @return void | |
*/ | |
public function initializeArguments() { | |
parent::initializeArguments(); | |
$this->registerUniversalTagAttributes(); | |
$this->registerArgument('path', 'string', 'Path to the resource', FALSE, FALSE); | |
} | |
/** | |
* @return string | |
*/ | |
public function render() { | |
if (FALSE === isset($this->arguments['path'])) { | |
$content = $this->renderChildren(); | |
} else { | |
$path = GeneralUtility::getFileAbsFileName(trim($this->arguments['path'], '../')); | |
$content = file_get_contents($path); | |
$content = PHP_EOL . trim($content) . PHP_EOL; | |
} | |
$this->tag->setContent($content); | |
$this->tag->forceClosingTag(TRUE); | |
$this->tag->addAttribute('type', 'text/ng-template'); | |
return $this->tag->render(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment