Twig Reference - xenocrat/chyrp-lite GitHub Wiki
Twig is Chyrp Lite's template engine. Each page of a Chyrp Lite website is constructed by processing one or more template files known as twigs, each of which provides a piece of the web page that will eventually be displayed to the visitor. Twig template files use a ".twig" file extension.
If you want to create or modify a template file, be sure to read the extensive documentation for designers and developers available at the Twig homepage.
Leaf is Chyrp Lite's Twig extension class. Leaf adds many useful functions and filters to the default set provided by the Twig template engine:
Name | Description |
---|---|
url() |
Return the canonical URL[note] for an action, optionally using the named Controller. |
self_url() |
Return the URL[note] of the current page. |
authenticate() |
Generates an authentication token for the session. |
module_enabled() |
Return true if the supplied module is enabled. |
feather_enabled() |
Return true if the supplied feather is enabled. |
password_strength() |
Returns a numeric score for strength of the supplied password. |
is_url() |
Does the string look like a web URL? |
is_email() |
Does the string look like an email address? |
generate_captcha() |
Generates a captcha form element. |
javascripts() |
Returns inline JavaScript for core functionality and extensions. |
paginate() |
Paginate the supplied array. |
posted() |
Returns a $_POST value if set, otherwise returns the supplied fallback value. |
mailto() |
Returns an obfuscated mailto: URL. |
icon_img() |
Returns a URL to the requested icon resource. |
uploaded_search() |
Returns an array of matches, if the visitor has the "edit_post" and "edit_page" privileges. |
javascripts_nonce() |
Returns a nonce value to enable inline JavaScript with a Content Security Policy. |
stylesheets_nonce() |
Returns a nonce value to enable inline stylesheets with a Content Security Policy. |
Modules may provide functions as callable methods in the form twig_function_<<name>>()
.
Name | Description |
---|---|
repeat |
Returns the supplied string, repeated n times. |
camelize |
Converts string to camelcase. |
decamelize |
Removes camelcase from a string. |
normalize |
Converts all excessive whitespace (including linebreaks) into a single space. |
truncate |
Truncates a string to the supplied maximum length. |
pluralize |
Returns the pluralization of a string, or if the supplied number is 1, don't pluralize. |
depluralize |
Undoes pluralization. |
markdown |
Applies Markdown formatting to the supplied text. |
emote |
Converts emoticons in the supplied text to Unicode emoji HTML entities. |
oneof |
Returns the first of the supplied values that has a substantial value. |
fix |
Neutralizes HTML, and optionally quotes, in the string. |
unfix |
Undoes neutralization of HTML and quotes in strings. |
sanitize |
Removes troublesome characters from a string, typically for class names. |
sanitize_html |
Disables scripts and obnoxious attributes in HTML. |
token |
Returns a salted and hashed SHA1 token using the string or array of strings. |
uploaded |
Returns an absolute URL for a file in the uploads directory. |
gravatar |
Retrieves an avatar image for the user, optionally within an <img> tag. |
add_scheme |
Prefixes a URL with a scheme if none was detected. |
lang_base |
Extracts the primary language subtag for the supplied code. |
text_direction |
Returns the correct text direction for the supplied language code. |
translate |
Translates the string using the default l10n domain, or optionally the supplied domain. |
translate_plural |
Translates the singular or supplied plural string, judged by the supplied number. |
time |
Returns a HTML element containing an internationalized time representation. |
dateformat |
Formats a timestamp using DateTime formatting rules. |
strftimeformat |
Returns a SQL-style YYYY-MM-DD HH:MM:SS format. Retained for backwards compatibility. |
filesizeformat |
Takes a number of bytes and displays it as "n KB", "n MB", or "n GB". |
preg_match |
Does a preg_match() on the subject with the supplied pattern or array of patterns. |
preg_replace |
Performs a preg_replace() on the supplied string or array. |
contains |
Searches a string, array, or object and returns true if it contains the supplied string. |
inspect |
Does var_export() on the variable and displays the result for inspection. |
selected |
Outputs a HTML selected attribute if the subject matches any of the supplied arguments. |
checked |
Outputs a HTML checked attribute if the subject evaluates to true . |
disabled |
Outputs a HTML disabled attribute if the subject matches any of the supplied arguments. |
download |
Returns a download link[note] for a file in the uploads directory. |
thumbnail |
Returns a thumbnail <img> tag for an uploaded image, optionally with enclosing <a> tag. |
Modules may provide filters as callable methods in the form twig_filter_<<name>>()
.