tatter/layouts

Layout management service for CodeIgniter 4

v1.0.0 2022-07-22 13:21 UTC

This package is auto-updated.

Last update: 2024-12-18 18:19:02 UTC


README

Layout management service for CodeIgniter 4

Coverage Status

Description

This library provides a commons means of managing View Layouts across package modules and applications.

Installation

Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities and always be up-to-date:

  • > composer require tatter/layouts

Or, install manually by downloading the source files and adding the directory to app/Config/Autoload.php.

Configuration

The code of Layouts amounts to a single config file: Tatter\Layouts\Config\Layouts. This file provides the path for each layout as a property. Initially the config file only includes a single property: "default". By supplying your own path via an App config file you can direct any package or module using Layouts to use your layout instead. For example, app/Config/Layouts.php:

<?php

namespace \Config;

class Layouts extends \Tatter\Layouts\Config\Layouts
{
	public $default = 'App\Views\project_layout';
}

Usage

To use the configured layout, simply provide the config property to your view file:

<?= $this->extend(config('Layouts')->default) ?>
<?= $this->section('main') ?>

	<p>Hellow world!</p>

<?= $this->endSection() ?>

You can use any layout name you have configured, and any name that does not match will fall back on the path supplied for "default".

See the CodeIgniter User Guide to read more on View Layouts

Layout Expectations

For consistency this library assumes that the "default" template will have the following sections:

  • headerAssets: The last section prior to the closing </head> tag, available for adding CSS tags and the like.
  • navbar: A navigation menu, typically to be displayed along the top of the page.
  • main: The main content for the page (can include nested views, etc).
  • footerASsets: The last section prior to the closing </body> tag, available for adding JS tags and footer content.

Default Layout

While it is highly recommended that you supply your own "default" layout, this library includes a generic one as a fallback. This layout is based on the Bootstrap Starter Template and includes CDN tags for Bootstrap CSS and JS. In addition to fulfilling the expectations above, the layout also accepts the following variables to configure the HTML <head> data:

  • $headerDescription
  • $headerAuthor
  • $headerTitle