Search by

kodhe / view

karyakode

Kodhe View & Template Engine (includes BladeOne)

Package info

github.com/kodhe/view

pkg:composer/kodhe/view

Statistics

Installs: 11

Dependents: 1

Suggesters: 2

Stars: 0

Open Issues: 0

1.1.0 2026-09-29 14:44 UTC

This package is not auto-updated.

Last update: 2026-10-28 10:37:26 UTC


README

A view/template package — a refactored version of the CodeIgniter 3 View system. It contains a ViewFactory supporting multiple template engines (native PHP, Blade via eftec/bladeone, and Twig) behind a single API, plus layout, theme, variant, and asset management (AssetManager). PSR-4 namespace: Kodhe\Framework\View\.

Installation

composer require kodhe/view

Requirements: PHP >= 8.1. Optional: twig/twig when using the Twig engine (Blade is already included via eftec/bladeone).

Quick Start

<?php

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use Kodhe\Framework\View\ViewFactory;

$view = new ViewFactory(['templatePath' => __DIR__ . '/app/views']);

// Render directly to the output
echo $view->render('welcome', ['title' => 'Hello World']);

// Or return it as a string (e.g. to wrap in a response)
$html = $view->view('welcome', ['title' => 'Hello'], return: true);

With the global helper (loaded automatically by composer files autoload):

echo view('welcome', ['title' => 'Hello World']);

Directory Structure

src/
├── ViewFactory.php        # Entry point: loads engines, renders, layouts
├── Engine/                # PhpEngine, BladeEngine, TwigEngine, EngineFactory
├── AssetManager.php       # CSS/JS registration & rendering
├── ThemeManager.php       # Multi-look theme support
├── VariantManager.php     # Template variants (e.g. mobile/desktop)
└── helpers/               # template.php, template_asset.php

Usage

1. Layout / master template

$view->layout('layouts/app');            // set the default layout
echo $view->render('pages/contact');     // content wrapped in the layout

2. Adding data incrementally

$view->set('user', $currentUser);        // key–value
$view->set(['siteName' => 'Kodhe', 'year' => 2026]); // array

3. Multiple engines in one project

$view->loadEngine('blade');
echo $view->render('dashboard.blade', $data);          // Blade-style

echo $view->render('email.twig', $data, engine: 'twig'); // use Twig once

4. Checking whether a template exists

if ($view->exists('pages/about')) {
    echo $view->render('pages/about');
}

Configuration (common)

Option Type Default Description
templatePath string APPPATH/views Base template folder
engine string php php, blade, or twig
theme string '' Active theme name (see ThemeManager)

CodeIgniter 3 Compatibility

  • The $this->load->view($name, $data, $return) calling style is preserved through render($view, $data, $return).
  • The procedural helpers in src/helpers/ are loaded via composer files, so old code calling view() keeps working.

Notes & Limitations

  • src/View.php is currently empty (0 bytes) — use ViewFactory as the official entry point; that file is a candidate for removal.
  • The Twig engine is not bundled; install twig/twig yourself if needed.

Testing

cd view && composer install && vendor/bin/phpunit

License

MIT. See LICENSE.