Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Template Hooks Bundle Laravel Package

braunstetter/template-hooks-bundle

View on GitHub
Deep Wiki
Context7

TemplateHooksBundle

Scrutinizer Code Quality Build Status Total Downloads License

Extend your twig templates without inheritance.

Installation

composer require braunstetter/template-hooks-bundle

Usage

You can use the hook tag inside your templates now:

{{ hook('app.cp.global-header') }}

Once you inserted this tag somewhere you and any bundles can hook into this by creating a class :

<?php


namespace App\Twig;


use Braunstetter\TemplateHooks\Twig\TemplateHook;

class BreadcrumbsHook extends TemplateHook
{

    /**
     * @inheritDoc
     */
    public function render(): string
    {
        return $this->templating->render('hooks/breadcrumbs.html.twig', $this->context);
    }

    public function setTarget(): string|array
    {
        return 'app.cp.global-header';
        
        // it would be possible to register to multiple hooks
        // return ['app.cp.global-header', 'app.cp.global-sidebar'];
    }
}

That's it. Your template gets rendered and you can process any logic before rendering it.

Ship javascript and css

With the use of AssetsPushBundle you can write inside hooks/breadcrumbs.html.twig:

{% css '/breadcrumbs.css' %}

The css or js will get included inside the head of the page.

For more information follow the official docs.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui