Heratio Framework API Reference

TemplateHelpers.php

Standalone template helper functions for WP4.

Provides the same API as Symfony 1.x template helpers for use in standalone mode (heratio.php). In dual-stack mode, Symfony's own helpers are loaded first, so these function_exists() guards prevent redeclaration.

Covers: url_for, link_to, include_partial, include_component, get_component, use_helper, use_stylesheet, use_javascript, format_date, format_number, image_tag, content_tag, tag, get_partial, slot, end_slot, has_slot, get_slot, include_slot, _compute_public_path

Table of Contents

Functions

url_for()  : string
Generate a URL for a route or resource.
_resolve_named_route()  : string
Resolve a named route (@name?params) to a URL.
link_to()  : string
Generate an HTML anchor tag.
include_partial()  : void
Render and output a partial template.
get_partial()  : string
Render a partial template and return as string.
include_component()  : void
Render and output a component (action + template).
get_component()  : string
Render a component and return as string.
slot()  : void
Start capturing content for a named slot.
end_slot()  : void
End the current slot capture.
has_slot()  : bool
Check if a named slot has content.
get_slot()  : string
Get the content of a named slot.
include_slot()  : bool
Output a named slot.
content_tag()  : string
Generate an HTML content tag.
tag()  : string
Generate a self-closing HTML tag.
image_tag()  : string
Generate an <img> tag.
_tag_options()  : string
Convert options array to HTML attribute string.
use_helper()  : void
Load a helper group. No-op in standalone mode.
use_stylesheet()  : void
Add a stylesheet to the response. No-op in standalone (assets handled by layout).
use_javascript()  : void
Add a JavaScript to the response. No-op in standalone.
format_date()  : string
Format a date value.
format_number()  : string
Format a number.
_compute_public_path()  : string
Compute a public path for an asset.
esc_entities()  : string
Escape HTML entities.
esc_raw()  : mixed
Return value without escaping (identity function).
csrf_field()  : string
Render a hidden input field containing the CSRF token.
csrf_token()  : string
Get the current CSRF token string.
csrf_meta()  : string
Render a meta tag containing the CSRF token for JS access.

Functions

url_for()

Generate a URL for a route or resource.

url_for(mixed $routeOrResource[, mixed $options = [] ]) : string

In Symfony mode this is provided by the Url helper. In standalone mode we handle the most common patterns:

  • String URL: returned as-is
  • Named route "@name?params": resolved via sfContext routing (if available)
  • Array with 'module'+'action': generates /module/action
  • Array with object + 'module': generates /module/slug
Parameters
$routeOrResource : mixed
$options : mixed = []
Return values
string

_resolve_named_route()

Resolve a named route (@name?params) to a URL.

_resolve_named_route(string $route) : string
Parameters
$route : string
Return values
string

Generate an HTML anchor tag.

link_to(string $text[, string|array<string|int, mixed> $url = '' ][, array<string|int, mixed> $options = [] ]) : string
Parameters
$text : string

Link text

$url : string|array<string|int, mixed> = ''

URL or route array

$options : array<string|int, mixed> = []

HTML attributes

Return values
string

include_partial()

Render and output a partial template.

include_partial(string $templateName[, array<string|int, mixed> $vars = [] ]) : void
Parameters
$templateName : string

"module/partial" or just "_partial"

$vars : array<string|int, mixed> = []

Variables to pass

get_partial()

Render a partial template and return as string.

get_partial(string $templateName[, array<string|int, mixed> $vars = [] ]) : string
Parameters
$templateName : string

"module/partial" or just "_partial"

$vars : array<string|int, mixed> = []

Variables to pass

Return values
string

include_component()

Render and output a component (action + template).

include_component(string $module, string $component[, array<string|int, mixed> $vars = [] ]) : void
Parameters
$module : string

Module name

$component : string

Component name

$vars : array<string|int, mixed> = []

Variables to pass

get_component()

Render a component and return as string.

get_component(string $module, string $component[, array<string|int, mixed> $vars = [] ]) : string
Parameters
$module : string

Module name

$component : string

Component name

$vars : array<string|int, mixed> = []

Variables to pass

Return values
string

slot()

Start capturing content for a named slot.

slot(mixed $name) : void
Parameters
$name : mixed

has_slot()

Check if a named slot has content.

has_slot(mixed $name) : bool
Parameters
$name : mixed
Return values
bool

get_slot()

Get the content of a named slot.

get_slot(mixed $name[, mixed $default = '' ]) : string
Parameters
$name : mixed
$default : mixed = ''
Return values
string

include_slot()

Output a named slot.

include_slot(mixed $name) : bool
Parameters
$name : mixed
Return values
bool

content_tag()

Generate an HTML content tag.

content_tag(string $tag[, string $content = '' ][, array<string|int, mixed>|string $options = [] ]) : string
Parameters
$tag : string

Tag name (e.g., 'div', 'span')

$content : string = ''

Tag content

$options : array<string|int, mixed>|string = []

HTML attributes

Return values
string

tag()

Generate a self-closing HTML tag.

tag(string $tag[, array<string|int, mixed>|string $options = [] ]) : string
Parameters
$tag : string

Tag name (e.g., 'br', 'hr', 'img')

$options : array<string|int, mixed>|string = []

HTML attributes

Return values
string

image_tag()

Generate an <img> tag.

image_tag(mixed $source[, mixed $options = [] ]) : string
Parameters
$source : mixed
$options : mixed = []
Return values
string

_tag_options()

Convert options array to HTML attribute string.

_tag_options(mixed $options) : string
Parameters
$options : mixed
Return values
string

use_helper()

Load a helper group. No-op in standalone mode.

use_helper(mixed ...$helpers) : void
Parameters
$helpers : mixed

use_stylesheet()

Add a stylesheet to the response. No-op in standalone (assets handled by layout).

use_stylesheet(mixed $css[, mixed $position = '' ][, mixed $options = [] ]) : void
Parameters
$css : mixed
$position : mixed = ''
$options : mixed = []

use_javascript()

Add a JavaScript to the response. No-op in standalone.

use_javascript(mixed $js[, mixed $position = '' ][, mixed $options = [] ]) : void
Parameters
$js : mixed
$position : mixed = ''
$options : mixed = []

format_date()

Format a date value.

format_date(mixed $date[, string $format = 'f' ][, string $culture = null ]) : string
Parameters
$date : mixed

Date string, timestamp, or DateTime object

$format : string = 'f'

Format string ('f' = full, 'D' = medium, 'p' = pattern, or PHP date format)

$culture : string = null

Culture code (unused in standalone — uses PHP locale)

Return values
string

format_number()

Format a number.

format_number(mixed $number[, mixed $culture = null ]) : string
Parameters
$number : mixed
$culture : mixed = null
Return values
string

_compute_public_path()

Compute a public path for an asset.

_compute_public_path(mixed $source[, mixed $dir = '' ][, mixed $ext = '' ]) : string
Parameters
$source : mixed
$dir : mixed = ''
$ext : mixed = ''
Return values
string

esc_entities()

Escape HTML entities.

esc_entities(mixed $value) : string
Parameters
$value : mixed
Return values
string

esc_raw()

Return value without escaping (identity function).

esc_raw(mixed $value) : mixed
Parameters
$value : mixed

csrf_field()

Render a hidden input field containing the CSRF token.

csrf_field() : string
Return values
string

csrf_token()

Get the current CSRF token string.

csrf_token() : string
Return values
string

csrf_meta()

Render a meta tag containing the CSRF token for JS access.

csrf_meta() : string
Return values
string

        
On this page

Search results