PHP code example of schivei / laravel-tag-helper
1. Go to this page and download the library: Download schivei/laravel-tag-helper library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
schivei / laravel-tag-helper example snippets
namespace Schivei\TagHelper\Helpers;
use Schivei\TagHelper\Helper;
use Schivei\TagHelper\Html\HtmlElement;
class CustomTagHelper extends Helper
{
protected $targetAttribute = 'custom';
protected $targetElements = ['div'];
protected function _process(HtmlElement $element)
{
// Manipulate the element
}
}
$this->app['tag-helper']->helper(CustomTagHelper::class);
class CustomTagHelper extends Helper
{
protected $targetAttribute = 'my-attribute';
// ...
}
namespace Schivei\TagHelper\Helpers;
use Schivei\TagHelper\Helper;
use Schivei\TagHelper\Html\HtmlElement;
class CustomLink extends Helper
{
protected $targetElement = 'my-custom-link';
protected function _process(HtmlElement $element)
{
$element->prependOuterHtml('<div class="custom-link">');
$element->appendOuterHtml('</div>');
}
}
namespace Schivei\TagHelper\Helpers;
use Schivei\TagHelper\Helper;
use Schivei\TagHelper\Html\HtmlElement;
class CustomLink extends Helper
{
protected $targetElement = 'my-custom-link';
protected function _process(HtmlElement $element)
{
$element->prependInnerHtml('<span class="custom-link">');
$element->appendInnerHtml('</span>');
$element->replaceInnerHtml('<span class="custom-link">Hello</span>');
}
}
namespace Schivei\TagHelper\Helpers;
use Schivei\TagHelper\Helper;
use Schivei\TagHelper\Html\HtmlElement;
class CustomLink extends Helper
{
protected $targetAttribute = 'route';
protected $targetElement = 'a';
protected function _process(HtmlElement $element)
{
$element->setAttribute('href', route($element->getAttribute('route')));
$element->setAttribute('title', 'This is a link.');
}
}
namespace Schivei\TagHelper\Helpers;
use Schivei\TagHelper\Helper;
use Schivei\TagHelper\Html\HtmlElement;
class CustomForm extends Helper
{
protected $targetElement = 'form';
protected function _process(HtmlElement $element)
{
$formMethod = $element->getAttribute('method');
}
}
namespace Schivei\TagHelper\Helpers;
use Schivei\TagHelper\Helper;
use Schivei\TagHelper\Html\HtmlElement;
class CustomForm extends Helper
{
protected $targetElement = 'a';
protected $targetAttribute = 'route';
protected function _process(HtmlElement $element)
{
$element->setAttribute('href', "{{ route(" . $element->getAttributeForBlade('route') . ") }}");
$element->removeAttribute('route');
}
}