dev-master
9999999-dev https://github.com/jhekasoft/HtmlShortcode.gitZF2 module that allows render view helpers using HTML-code.
The Requires
- php >=5.3.3
- zendframework/zend-version 2.*
Wallogit.com
2017 © Pedro Peláez
ZF2 module that allows render view helpers using HTML-code.
Module for Zend Framework 2 that allows render view helpers using HTML-code. You can use this module with editors like TinyMCE and CKEditor., (*1)
php composer.phar require jhekasoft/html-shortcode:dev-master
In application.config.php add the following key to your modules:, (*2)
'modules' => array(
//...
'HtmlShortcode',
),
At controller:, (*3)
//...
use HMShortCode\Filter\ShortCodeFilter;
class IndexController
{
public function showAction()
{
//...
$shortCodeFilter = new ShortCodeFilter();
$shortCodeFilter->setServiceLocator($this->getServiceLocator());
$item->text = $shortCodeFilter->filter($item->text);
return array(
'item' => $item,
);
}
}
At entity:, (*4)
//...
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use HtmlShortcode\Filter\ShortcodeFilter;
class Pages implements InputFilterAwareInterface, ServiceLocatorAwareInterface
{
public function exchangeArray($data)
{
$this->text = (isset($data['text'])) ? $data['text'] : null;
// ShortCode filter
$shortcodeFilter = new ShortcodeFilter();
$shortcodeFilter->setServiceLocator($this->getServiceLocator());
$this->filtered_text = $shortcodeFilter->filter($this->text);
}
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
return $this;
}
public function getServiceLocator()
{
return $this->serviceLocator;
}
}
On bootstrap (except edit action):, (*5)
//...
public function onBootstrap($e)
{
$app = $e->getApplication();
$em = $app->getEventManager();
$em->attach(\Zend\Mvc\MvcEvent::EVENT_ROUTE, function($e) {
$match = $e->getRouteMatch();
$action = $match->getParam('action');
if ('edit' != $action) {
$sm = $e->getApplication()->getServiceManager();
$view = $sm->get('ViewRenderer');
$filters = $view->getFilterChain();
$widgetFilter = new ShortCodeFilter();
$widgetFilter->setServiceLocator($sm);
$filters->attach($widgetFilter, 50);
$view->setFilterChain($filters);
}
});
}
Samples:, (*6)
<span class="htmlshortcode" data-helper="soundBlock" data-params="[value1]"></div>
<span class="htmlshortcode" data-helper="soundBlock" data-params='[value3][{"size":"small"}]'></span>
Second parameter in last example is in JSON format., (*7)
The examples above are equivalent this php-code in view-script:, (*8)
echo $this->soundBlock('value1');
echo $this->soundBlock('value2');
echo $this->soundBlock('value3', array("size" => "small"));
ZF2 module that allows render view helpers using HTML-code.