Weave 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

Twig Php Function Laravel Package

umpirsky/twig-php-function

Lightweight Twig extension that lets you call any PHP function directly from your templates with a simple php_function() call. Skip writing custom Twig extensions for quick formatting, hashing, or utility helpers. Works with Twig 2 and 3.

Deep Wiki
Context7

Product Decisions This Supports

  • Template flexibility vs. developer velocity: This package lets template authors invoke PHP functions directly, which reduces the "open a ticket, wait for an engineering sprint" loop for small template-driven display needs.
  • Build vs. buy for Twig helpers: Instead of hand-writing a custom TwigFunction/filter for every PHP helper you want exposed, this is a generic pass-through. It replaces a build task with a dependency add.
  • Evaluating a Blade→Twig migration (e.g., via twigbridge in a Laravel app): this is a tactical unblocker that lets existing PHP helpers keep working in templates while you plan a curated Twig extension set.
  • Scoping a "trusted template authors" initiative: if your roadmap includes letting internal staff (marketers, support, ops) edit templates, this package frames the security/trust decision you'll need to make explicit.
  • Prototyping and internal tooling: for throwaway admin panels, reporting templates, or migration spikes, this is the fastest path to exposing arbitrary PHP functionality without dedicated engineering work.
  • Roadmap signaling: adopting it (or explicitly rejecting it) is a decision about how much control you want over the template surface area — generic escape hatches accelerate today and accumulate governance debt tomorrow.

When to Consider This Package

Consider adopting when:

  • Your stack actually uses Twig. Laravel ships with Blade by default, so this only applies if you've added Twig via twigbridge or are running a non-Laravel PHP app. If you're Blade-only, this package is irrelevant.
  • Template authors are trusted. You control who writes templates (internal developers, vetted staff) and treat templates as code, not user input.
  • You need a broad, evolving set of PHP helpers in templates and writing one Twig extension per function would be busywork.
  • You're in a migration or prototype phase where speed beats elegance, and you expect to replace this with a curated function/filter set later.
  • You want a tiny, MIT-licensed, zero-infrastructure dependency with an obvious, auditable behavior surface.

Look elsewhere when:

  • Templates can be authored or edited by untrusted users or end customers. Calling arbitrary PHP functions from templates is a serious security and reviewability risk — you'd want an explicit allow-list of Twig functions/filters instead.
  • You need type safety, discoverability, or IDE support for the functions exposed to templates; a curated extension set is better.
  • The template surface is stable and small. Writing your own TwigExtension with named functions/filters is cheaper in cognitive load than a generic escape hatch.
  • You're on Blade and not planning to migrate. No value.
  • Maintenance posture matters more than convenience. Small-star-count packages deserve a maintenance and abandonment check; if the package is unmaintained, you may prefer a few lines of your own extension code.
  • You need guardrails such as per-function argument validation, sandboxing, or logging — none of which a generic pass-through is designed to provide.

How to Pitch It (Stakeholders)

For executives: This is a small, MIT-licensed Twig extension that lets templates call PHP functions directly. It's a low-cost, low-risk way to unblock template flexibility and reduce engineering handoffs for small template changes. The trade-off is governance: because it can call almost any PHP function, it should only be used where template authors are trusted. Recommend a time-boxed trial in a non-customer-facing or internal-tooling context, with a planned exit toward a curated, allow-listed Twig extension set as usage matures.

For engineering: A thin, transparent Twig extension — one dependency, no infrastructure, trivial to integrate where Twig is already in play (note: requires Twig via twigbridge or equivalent; not applicable to a Blade-only Laravel app). The core concern is security and maintainability: treating templates as trusted code is a prerequisite, and we should plan to replace the generic pass-through with explicit TwigFunction/filter registrations for any function that becomes load-bearing. Also worth a quick maintenance check given the package's small footprint before we depend on it in production.

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.
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle