Cecil

Content extends AbstractExtension

Content Twig extension.

Provides filters and functions for content processing in Twig templates, including text manipulation, Markdown rendering, and data parsing.

Table of Contents

Properties

$builder  : Builder
$config  : Config

Methods

__construct()  : mixed
excerpt()  : string
Reads $length first characters of a string and adds a suffix.
excerptHtml()  : string
Reads characters before or after '<!-- separator -->'.
getFilters()  : array<string|int, mixed>
getFunctions()  : array<string|int, mixed>
hexToRgb()  : array<string|int, mixed>
Converts an hexadecimal color to RGB.
highlight()  : string
Highlights a code snippet.
iterable()  : array<string|int, mixed>
Converts a variable to an iterable (array).
jsonDecode()  : array<string|int, mixed>|null
Converts a JSON string to an array.
markdownToHtml()  : string|null
Converts a Markdown string to HTML.
markdownToToc()  : string|null
Extracts only headings matching the given `selectors` (h2, h3, etc.), or those defined in config `pages.body.toc` if not specified.
pregMatchAll()  : array<string|int, mixed>|null
Perform a regular expression match and return the group for all matches.
pregSplit()  : array<string|int, mixed>|null
Split a string into an array using a regular expression.
readtime()  : string
Calculates estimated time to read a text.
slugifyFilter()  : string
Slugifies a string.
splitLine()  : array<string|int, mixed>
Split a string in multiple lines.
unique()  : array<string|int, mixed>
Returns an array with unique values.
yamlParse()  : array<string|int, mixed>|null
Converts a YAML string to an array.
isHex()  : bool
Is a hexadecimal color is valid?

Properties

Methods

excerpt()

Reads $length first characters of a string and adds a suffix.

public excerpt(string|null $string[, int $length = 450 ][, string $suffix = ' …' ]) : string
Parameters
$string : string|null
$length : int = 450
$suffix : string = ' …'
Return values
string

excerptHtml()

Reads characters before or after '<!-- separator -->'.

public excerptHtml(string|null $string[, array<string|int, mixed> $options = [] ]) : string

Options:

  • separator: string to use as separator (excerpt|break by default)
  • capture: part to capture, before or after the separator (before by default).
Parameters
$string : string|null
$options : array<string|int, mixed> = []
Return values
string

getFilters()

public getFilters() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFunctions()

public getFunctions() : array<string|int, mixed>
Return values
array<string|int, mixed>

hexToRgb()

Converts an hexadecimal color to RGB.

public hexToRgb(string|null $variable) : array<string|int, mixed>
Parameters
$variable : string|null
Tags
throws
RuntimeException
Return values
array<string|int, mixed>

highlight()

Highlights a code snippet.

public highlight(string $code, string $language) : string
Parameters
$code : string
$language : string
Return values
string

iterable()

Converts a variable to an iterable (array).

public iterable(mixed $value) : array<string|int, mixed>
Parameters
$value : mixed
Return values
array<string|int, mixed>

jsonDecode()

Converts a JSON string to an array.

public jsonDecode(string|null $json) : array<string|int, mixed>|null
Parameters
$json : string|null
Tags
throws
RuntimeException
Return values
array<string|int, mixed>|null

markdownToHtml()

Converts a Markdown string to HTML.

public markdownToHtml(string|null $markdown) : string|null
Parameters
$markdown : string|null
Tags
throws
RuntimeException
Return values
string|null

markdownToToc()

Extracts only headings matching the given `selectors` (h2, h3, etc.), or those defined in config `pages.body.toc` if not specified.

public markdownToToc(string|null $markdown[, mixed $format = 'html' ][, array<string|int, mixed>|null $selectors = null ][, string $url = '' ]) : string|null

The format parameter defines the output format: html or json. The url parameter is used to build links to headings.

Parameters
$markdown : string|null
$format : mixed = 'html'
$selectors : array<string|int, mixed>|null = null
$url : string = ''
Tags
throws
RuntimeException
Return values
string|null

pregMatchAll()

Perform a regular expression match and return the group for all matches.

public pregMatchAll(string|null $value, string $pattern[, int $group = 0 ]) : array<string|int, mixed>|null
Parameters
$value : string|null
$pattern : string
$group : int = 0
Tags
throws
RuntimeException
Return values
array<string|int, mixed>|null

pregSplit()

Split a string into an array using a regular expression.

public pregSplit(string|null $value, string $pattern[, int $limit = 0 ]) : array<string|int, mixed>|null
Parameters
$value : string|null
$pattern : string
$limit : int = 0
Tags
throws
RuntimeException
Return values
array<string|int, mixed>|null

readtime()

Calculates estimated time to read a text.

public readtime(string|null $text) : string
Parameters
$text : string|null
Return values
string

slugifyFilter()

Slugifies a string.

public slugifyFilter(string $string) : string
Parameters
$string : string
Return values
string

splitLine()

Split a string in multiple lines.

public splitLine(string|null $variable[, int $max = 18 ]) : array<string|int, mixed>
Parameters
$variable : string|null
$max : int = 18
Return values
array<string|int, mixed>

unique()

Returns an array with unique values.

public unique(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

yamlParse()

Converts a YAML string to an array.

public yamlParse(string|null $yaml) : array<string|int, mixed>|null
Parameters
$yaml : string|null
Tags
throws
RuntimeException
Return values
array<string|int, mixed>|null

isHex()

Is a hexadecimal color is valid?

private static isHex(string $hex) : bool
Parameters
$hex : string
Return values
bool
On this page

Search results