New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

fortephp/forte

A fault-tolerant Blade template parser and AST toolkit.
21,824 69

Larablocks Analysis

fortephp/forte works with Laravel 10 to 13 (latest release v1.1.0, Aug 22, 2026).

Recommendation checks

Solid choice

Solid choice: maintained and up to date, meets 3 of 4 checks; below the bar for Recommended on use.

  • Works with Laravel 13, the current version
  • Released in the last 12 months (Aug 22, 2026)
  • 10,084 downloads a month (at least 10,000)
  • 69 GitHub stars (needs 100)

State

Actively maintained
  • Last stable release: Aug 22, 2026.
  • 11 releases in the last 12 months.
  • First released: Jan 14, 2026.
  • Monthly downloads: 10,084, up 31413% from six months ago.
  • 1 open issue on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 28, 2026.

Install
composer require fortephp/forte
Latest Version:v1.1.0
PHP:^8.2
Laravel:10 – 13
License:MIT
Last Updated:Sep 16, 2026
Links: GitHub  ·  Packagist
Maintainer: stillat

Forte

the ... strongest part of the blade

https://www.merriam-webster.com/dictionary/forte

Forte is a Laravel Blade parser and AST manipulation library.

Quick Start

use Forte\Facades\Forte;
use Forte\Rewriting\NodePath;

// Parse a Blade template into a document
$doc = Forte::parse('<div class="mt-4">Hello, {{ $name }}!</div>');

// Query with XPath
$divs = $doc->xpath('//div[@class]')->get();

// Rewrite (returns a new document, original is unchanged)
$newDoc = $doc->rewriteWith(function (NodePath $path) {
    if ($path->isTag('div')) {
        $path->removeClass('mt-4');
        $path->addClass('container');
    }
});

echo $newDoc->render(); // <div class="container">Hello, {{ $name }}!</div>

Core Features

Parsing

Forte's three-phase pipeline (lexer, tree builder, document) handles valid and malformed input alike, recovering gracefully with diagnostics.

$doc = Forte::parse($bladeTemplate);
$doc = Forte::parseFile('resources/views/welcome.blade.php');

Immutable Documents

Every mutation returns a new Document instance. Safe to hold references, chain transformations, and compare before/after states.

Tree Traversal and Querying

Walk the tree, find nodes by predicate, or query with XPath 1.0. Blade constructs map to namespaced elements (forte:if, forte:echo) for XPath queries.

use Forte\Ast\TraversalOptions;

// Lazy, fluent collections with optional name filters
$forms = $doc->queryElements('form');
$conditionals = $doc->queryBlockDirectives(['if', 'unless']);
$components = $doc->queryComponents(['x-alert', 'livewire:*']);

// Fast exact lookups and convenient existence checks
$navigation = $doc->elementById('primary-navigation');
$hasHead = $doc->hasElement('head');

// Attribute semantics live on Attribute; ElementNode provides null-safe proxies
$form = $doc->firstElement('form');
$method = $form?->attribute('method');
$isDynamic = $method?->isDynamic() ?? false;
$staticMethod = $form?->staticAttributeValueLower('method');
$classes = $form?->attributeTokens('class') ?? [];

// Navigate relationships without rebuilding ancestor/descendant loops
$owner = $navigation?->closestElement('header');
$links = $navigation?->descendantElements('a');

// Include attribute/tag-name internals when a deep semantic scan is needed
$allEchoes = $doc->allEchoes(TraversalOptions::deep());

// XPath
$doc->xpath('//forte:if')->get();

The original getElements(), findElementsByName(), magic collection properties, and other released query methods remain available. The query* methods add Laravel-style lazy collections without changing those existing contracts.

Rewriting

The visitor pattern with queued operations prevents excessive intermediate documents. Use NodePath for all mutations, including CSS class helpers, attribute manipulation, and structural changes.

$doc->rewriteWith(function (NodePath $path) {
    if ($path->isTag('center')) {
        $path->renameTag('div');
        $path->addClass('text-center');
    }
});

Components and Directives

First-class support for Blade components (<x-alert>), slots (<x-slot:header>), and all directive types (standalone @csrf, blocks @if...@endif).

$component = $doc->findComponentByName('x-alert');
$directive = $doc->find(fn ($n) => $n->isDirectiveNamed('foreach'));

Node Builders

Construct synthetic nodes for replacements and insertions with a fluent API.

use Forte\Rewriting\Builders\Builder;

Builder::element('div')->class('wrapper')->text('Hello');
Builder::directive('if', '($show)');
Builder::echo('$name');

To learn more, visit https://fortephp.com.

License

Forte is free software, released under the MIT license.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

670,032,257 9,703
laravel/framework

The Laravel Framework.

640,572,096 35,338
laravel/tinker

Powerful REPL for the Laravel framework.

546,909,908 7,440
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

465,816,364 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

431,187,642 4,660

Version History

Version Released PHP Laravel License
v1.1.0 ^8.2 ^10 || ^11 || ^12 || ^13 MIT
v1.0.4 ^8.2 ^10 || ^11 || ^12 || ^13 MIT
v1.0.3 ^8.2 ^10 || ^11 || ^12 || ^13 MIT
v1.0.2 ^8.2 ^10 || ^11 || ^12 || ^13 MIT
v1.0.1 ^8.2 ^10 || ^11 || ^12 || ^13 MIT