Search
Blade Parser

Blade Parser

Custom Component Tags

The document parser supports registering custom component tag prefixes. By default, the parser is configured to parse elements beginning with <x-, <x:, </x, or </x: as Blade component tags; this behavior cannot be changed.

However, we can add custom component tag prefixes using the registerCustomComponentTag or registerCustomComponentTags methods:

1<?php
2 
3use Stillat\BladeParser\Parser\DocumentParser;
4 
5$parser = new DocumentParser;
6 
7// Register a single custom component prefix.
8$parser->registerCustomComponentTag('c');
9 
10// Register multiple custom component prefixes.
11$parser->registerCustomComponentTags([
12 'a', 'b', 'c',
13]);

The document parser will parse all custom component tag prefixes as if they were Blade components and provide all relevant information, such as parameters, tag names, namespaces, etc.

With our custom component tag prefixes, all of the following would be equivalent:

1<a-alert :$message />
2<b-alert :$message />
3<c-alert :$message />
4<x-alert :$message />

#Custom Component Tag Compilation

To learn how to modify the compilation behavior of custom components, please consult the article Compiling Custom Components.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.