Kotchasan

Grid extends Template
in package

This class represents a grid system used for layout purposes.

Tags
see
https://www.kotchasan.com/

Table of Contents

$cols  : int
Number of columns for grid display
$items  : array<string|int, mixed>
Array of data
$num  : int
Variable for line break (Grid)
$src  : string
Name of the currently used template including the folder where the template is stored Starting from DOCUMENT_ROOT, e.g., skin/default/
$skin  : string
Template data
__construct()  : mixed
Constructor
add()  : static
Sets the template variables This function replaces all variables with the provided values in the template immediately
create()  : static
Loads a template It checks the module's file first, if not found, it uses the owner's file
createFromFile()  : static
Loads a template from a file
createFromHTML()  : static
Creates a template from HTML
get()  : string
Returns the directory of the template starting from DOCUMENT_ROOT
getCols()  : int
Get the number of columns in the grid.
hasItem()  : bool
Checks if data has been added to the template
init()  : mixed
Sets the template to be used
insertHTML()  : static
Inserts HTML into the template directly Used to insert HTML between items
isEmpty()  : bool
Checks if the Template file is empty
load()  : string
Loads a template It checks the module's file first, if not found, it uses the owner's file If not found, it returns an empty string
pregReplace()  : string
Executes the preg_replace function
render()  : string
Returns the rendered HTML
setCols()  : static
Set the number of columns in the grid.

Properties

$cols

Number of columns for grid display

protected int $cols

The number of columns in the grid

$items

Array of data

protected array<string|int, mixed> $items

$num

Variable for line break (Grid)

protected int $num

$src

Name of the currently used template including the folder where the template is stored Starting from DOCUMENT_ROOT, e.g., skin/default/

protected static string $src

$skin

Template data

private string $skin

Methods

__construct()

Constructor

public __construct() : mixed
Return values
mixed

add()

Sets the template variables This function replaces all variables with the provided values in the template immediately

public add(array<string|int, mixed> $array) : static
Parameters
$array : array<string|int, mixed>

An array of variable names and their corresponding values to be replaced in the template Format: array(key1=>val1,key2=>val2)

Return values
static

create()

Loads a template It checks the module's file first, if not found, it uses the owner's file

public static create(string $owner, string $module, string $name) : static
Parameters
$owner : string

The name of the installed module

$module : string

The name of the module

$name : string

The name of the template without the file extension

Tags
assert

('', '', 'FileNotFound')->isEmpty() [==] true

Return values
static

createFromFile()

Loads a template from a file

public static createFromFile(string $filename) : static
Parameters
$filename : string

The filename

Tags
assert

('FileNotFound') [throws] InvalidArgumentException

throws
InvalidArgumentException

If the file is not found

Return values
static

createFromHTML()

Creates a template from HTML

public static createFromHTML(string $html) : static
Parameters
$html : string

The HTML code

Return values
static

get()

Returns the directory of the template starting from DOCUMENT_ROOT

public static get() : string
Return values
string

getCols()

Get the number of columns in the grid.

public getCols() : int
Return values
int

The number of columns

hasItem()

Checks if data has been added to the template

public hasItem() : bool
Return values
bool

Returns true if the add function has been called before, false otherwise

init()

Sets the template to be used

public static init(string $skin) : mixed
Parameters
$skin : string

The directory of the template starting from DOCUMENT_ROOT without a trailing slash, e.g., skin/default

Return values
mixed

insertHTML()

Inserts HTML into the template directly Used to insert HTML between items

public insertHTML(string $html) : static
Parameters
$html : string

The HTML code

Return values
static

isEmpty()

Checks if the Template file is empty

public isEmpty() : bool
Return values
bool

Returns true if the Template file is empty or not found, false otherwise

load()

Loads a template It checks the module's file first, if not found, it uses the owner's file If not found, it returns an empty string

public static load(string $owner, string $module, string $name) : string
Parameters
$owner : string

The name of the installed module

$module : string

The name of the registered module

$name : string

The name of the template without the file extension

Return values
string

pregReplace()

Executes the preg_replace function

public static pregReplace(array<string|int, mixed> $patt, array<string|int, mixed> $replace, string $skin) : string
Parameters
$patt : array<string|int, mixed>

The keys in the template

$replace : array<string|int, mixed>

The text to replace the keys

$skin : string

The template

Tags
assert

('/{TITLE}/', 'Title', '{TITLE}') [==] 'Title'

assert

('/{LNG_([\w\s.-'(),%/:&#;]+)}/e', '\Kotchasan\Language::parse(array(1=>"$1"))', '{LNG_Language test}') [==] 'Language test'

Return values
string

render()

Returns the rendered HTML

public render() : string
Return values
string

setCols()

Set the number of columns in the grid.

public setCols(int $cols) : static
Parameters
$cols : int

The number of columns (must be greater than 0)

Return values
static

This Grid instance for method chaining

Search results