Twig Reference

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

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:

Functions

NameDescription
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.
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.
uploaded_search()Returns an array of matches, if the visitor has the "edit_post" and "edit_page" privileges.

Modules may provide functions as callable methods in the form twig_function_<<name>>().

Filters

NameDescription
repeatReturns the supplied string, repeated n times.
camelizeConverts string to camelcase.
decamelizeRemoves camelcase from a string.
normalizeConverts all excessive whitespace (including linebreaks) into a single space.
truncateTruncates a string to the supplied maximum length.
pluralizeReturns the pluralization of a string, or if the supplied number is 1, don't pluralize.
depluralizeUndoes pluralization.
markdownApplies Markdown formatting to the supplied text.
emoteConverts emoticons in the supplied text to Unicode emoji HTML entities.
oneofReturns the first of the supplied values that has a substantial value.
fixNeutralizes HTML, and optionally quotes, in the string.
unfixUndoes neutralization of HTML and quotes in strings.
sanitizeRemoves troublesome characters from a string, typically for class names.
sanitize_htmlDisables scripts and obnoxious attributes in HTML.
tokenReturns a salted and hashed SHA1 token using the string or array of strings.
uploadedReturns an absolute URL for a file in the uploads directory.
gravatarRetrieves an avatar image for the user, optionally within an <img> tag.
add_schemePrefixes a URL with a scheme if none was detected.
lang_baseExtracts the primary language subtag for the supplied code.
translateTranslates the string using the default l10n domain, or optionally the supplied domain.
translate_pluralTranslates the singular or supplied plural string, judged by the supplied number.
timeReturns a
dateformatFormats a timestamp using DateTime formatting rules.
strftimeformatReturns a SQL-style YYYY-MM-DD HH:MM:SS format. Retained for backwards compatibility.
filesizeformatTakes a number of bytes and displays it as "n KB", "n MB", or "n GB".
preg_matchDoes a preg_match() on the subject with the supplied pattern or array of patterns.
preg_replacePerforms a preg_replace() on the supplied string or array.
containsSearches a string, array, or object and returns true if it contains the supplied string.
inspectDoes var_export() on the variable and displays the result for inspection.
selectedOutputs a HTML selected attribute if the subject matches any of the supplied arguments.
checkedOutputs a HTML checked attribute if the subject evaluates to true.
disabledOutputs a HTML disabled attribute if the subject matches any of the supplied arguments.
downloadReturns a download link[note] for a file in the uploads directory.
thumbnailReturns 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>>().