Download the PHP package schivei/laravel-tag-helper without Composer

On this page you can find all versions of the php package schivei/laravel-tag-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-tag-helper

Laravel Tag Helpers

Latest Version on Packagist Build Status codecov Total Downloads

This package allows you to register custom "tag helpers" in your Laravel application. These helpers can modify the HTML code.

It is a fork of beyondcode/laravel-tag-helper

What the difference between this package and the original one?

This package is focused on element attributes, while the original proposes to implement custom elements. This package also has a better test coverage and a more robust codebase.

To use custom elements, try to create Blade Components instead.

Why should I use this package?

To create shortcuts for common HTML patterns and reduce the double bracket usage in your Blade templates.

Built-In Helpers

CSRF Token

Instead of writing this:

You can write this:

Form Method

Instead of writing this:

You can write this:

Link

Instead of writing this:

You can write this:

Assets

Instead of writing this:

You can write this:

Conditional Attributes

Instead of writing this:

You can write this:

NOTE: else and elseif are not supported.

Guest and Auth

Instead of writing this:

You can write this:

Installation

You can install the package via composer:

Usage

You can create your own Tag Helper, by creating a new class and extend from the Schivei\TagHelper\Helper class. Within this class you can define on which HTML elements and attributes your helper should be triggered:

To use and apply this tag helper, you need to register it. Typically, you would do this in the AppServiceProvider boot() method or a service provider of your own.

Pay attention, the $autoRemoveAttribute property is set to true by default. If you do not want to remove the attribute after processing, you can set it to false.

Since you only register the class name of the custom tag helper, you can use dependency injection inside your custom helper class.

Binding your helper to HTML elements and attributes

In your custom tag helper, you can use the $targetAttribute and $targetElements properties to specify which HTML element (div, form, a, etc.) and attributes (<div custom="value />, <form method="post">, etc.) you want to bind this helper to.

If you do not provide a targetElements on your own, this package will target to all elements with a specific attribute, like this:

This tag helper would be called for every HTML element that has a my-attribute attribute.

Manipulating DOM Elements

Once your tag helper successfully matches one or multiple HTML elements, the process method of your tag helper will be called.

Inside of this method, you can manipulate the HTML element.

Available features:

Prepend / Append outer HTML

You can add HTML before or after the current element.

Prepend / Append / Replace inner HTML

You can add HTML inside the current element, only if the element is not self-closing only.

Manipulating Attributes

You can also add, edit or delete HTML element attributes.

In this example, we are binding our helper to all link tags that have a custom route attribute. We then update the href attribute of our link, remove the route attribute and add a new title attribute.

Passing variables to your tag helpers

You can pass attribute values to your tag helpers as you would usually pass attributes to HTML elements. Since the modifications of your tag helpers get cached, you should always return valid Blade template output in your modified attribute values.

You can not directly access the variable content inside your tag helper, but only get the attribute string representation.

For example, to get the attribute value of the method attribute:

You can access this data, using the getAttribute method inside your helper:

If you want to write Blade output, you sometimes need to know if the user passed a variable or function call, or a string value. To tell the difference, users can pass variable data by prefixing the attribute using a colon.

If you want to output this attribute into a blade template, you can then use the getAttributeForBlade method, and it will either give you an escaped string representation of the attribute - or the unescaped representation, in case it got prefixed by a colon.

For example:

This will output:

But if you pass a dynamic parameter like this:

This will output:

This way you do not need to manually care about escaping and detecting dynamic variables.

Testing

Changelog

Please see Releases for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-tag-helper with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
paquettg/php-html-parser Version ^2.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package schivei/laravel-tag-helper contains the following files

Loading the files please wait ....