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

Php Template Laravel Package

yakeing/php_template

yakeing/php_template is a lightweight PHP templating package for separating HTML views from application logic. It provides a straightforward way to render templates and pass data into them, making it useful for small projects or for adding simple view rendering without a full framework.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install: composer require yakeing/php_template — but pin the exact version ("yakeing/php_template": "1.0.x") or vendor the source, since the project is archived and last released 2019-08-08. There is no active maintainer, no security patches, and Composer updates could break you silently.
  • Read the repo in this order: README.md → src/ (the template engine class) → tests/ if present. Because the project is small (~32 stars, single-purpose), the entire source is the documentation. Grep for preg_match, preg_replace, or str_replace in the engine to understand exactly which tags are supported — don't trust the README alone.
  • First use case: rendering a static HTML page with a few dynamic values (page title, user name, list of items). This is the package's happy path:
    $tpl = new \Yakeing\Template\Template();
    $tpl->assign('title', 'Home');
    $tpl->assign('user',  $user);
    $tpl->assign('items', $items);
    $tpl->display('index.tpl');
    
    Confirm the constructor / directory configuration against the README — set a template directory and a compile/cache directory before the first render.
  • Sanity check: after the first display(), open the compiled output (usually a cache/ or runtime/ directory) and read the generated PHP. That file is your ground truth for how every tag compiles.

Implementation Patterns

  • Bootstrap once, render many times. Instantiate the template engine in your front controller or a small service wrapper — not per-include. A thin wrapper (View::render($file, $data)) gives you a single place to swap the engine later (Smarty, Blade, Twig) if you outgrow it.
  • Assign vs. render-time data. Prefer passing an associative array at render time ($tpl->assign($data) in a loop, or $tpl->display($file, $data) if supported) over dozens of assign() calls. It keeps controllers clean and matches how the template will actually consume the data.
  • Layout + partials. Since this is a compile-to-PHP engine, you'll typically get an {include file="header.tpl"}-style tag or none at all. If includes aren't supported, build the layout in PHP: render the partial, capture the output, and inject into the layout string. Document the chosen approach in your project README — future you (or a teammate) will otherwise reinvent it.
  • Loops and conditionals. Typical syntax is {foreach $items as $item}...{/foreach} and {if $cond}...{/if} (verify exact tags in src/). Wrap repeated table rows, cards, and nav items in loops rather than echoing HTML inside PHP foreach blocks — that's the whole point of adopting a template engine.
  • Escaping discipline. Assume tags output raw values. For every user-supplied field ($_GET, form input, DB text rendered as HTML), call htmlspecialchars($v, ENT_QUOTES, 'UTF-8') in the controller or escape tag ({$v|escape} if supported) in the template. Write a small helper e() and standardize on it.
  • Cache the compile step in production. A compile-to-PHP engine usually checks the template's mtime on every request. Set the compile/cache path to a writable directory not served by the web server (storage/templates_compiled/), and disable mtime checks in production if the config exposes that flag.
  • Integration pattern for legacy PHP apps. Drop it into an existing index.php-style app: keep routing/CRUD in PHP, call the renderer only at the end. This avoids a big-bang refactor and lets you adopt the engine per-page.
  • Testing pattern. Because output is deterministic, unit-test by asserting on the rendered string: $this->assertStringContainsString('Hello Alice', View::render('greeting.tpl', ['name' => 'Alice'])). This catches syntax regressions when you eventually migrate off the package.

Gotchas and Tips

  • The package is archived. No bug fixes, no PHP 8 compatibility guarantees. The source predates PHP 7.4 typed properties and PHP 8's stricter warnings. Test on your target PHP version first; if it emits deprecations or fails to compile on PHP 8, either pin PHP 7.4/8.0 or fork the source into your app/Libraries/ directory and fix it locally. Never rely on composer update to fix anything.
  • Compilation failures are silent-ish. If a template throws, the error usually surfaces in the compiled file, not the template. When debugging, look at the compiled artifact and the line number it points to, then map it back to the .tpl by re-reading the raw file. Add a try/catch around render calls in dev and dump the compiled source on failure.
  • Cache invalidation is the #1 support issue. In development, mtime-based invalidation often misses {include}d templates — you edit header.tpl, see no change, and blame the engine. Keep a clear cache script (rm -rf storage/templates_compiled/*) and run it after every pull or template edit. Wire it into a dev-only route or Artisan-style command.
  • Directory permissions. The compile directory must exist and be writable by the web user (www-data), not just your shell user. Symptom: blank pages or "failed to open stream" warnings. chmod -R 775 the compile dir and chown it correctly.
  • Path traversal risk with dynamic template names. If any template path is built from user input ($tpl->display($_GET['page'] . '.tpl')), you've reintroduced an LFI vector. Validate against a whitelist of known templates — this is a template engine, not a router.
  • XSS by default. Raw variable output is the common default. Audit every template for {$user_input} and route it through htmlspecialchars(). The engine will not save you here, and with no maintainer there will never be a security patch for an escape-related bug.
  • Tag syntax is regex-based, so whitespace and quoting matter. {if $a=="b"} may parse where {if $a == "b"} fails (or vice versa), and nested quotes/braces in expressions can break the compiler. Keep conditions simple in templates; compute complex logic in PHP and pass a boolean.
  • Extension points are minimal. The engine likely exposes at most a custom-function/delimiter hook. Don't plan on plugins, middleware, or an event system. If you need custom filters, wrap the renderer: post-process the returned string in PHP, or pre-escape data before assign().
  • Migration path up front. Because this package will not be maintained, treat adoption as a bridge: isolate rendering behind a View class so you can switch to Twig or Blade later without touching controllers. If the project has a multi-year lifespan, seriously consider starting with an actively maintained engine instead.
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