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 visitor.
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.
paginate()Paginate the supplied array.
posted()Returns a $_POST value if set, otherwise returns the supplied fallback value.
mailto()Returns an obfuscated mailto: URL.

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.
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.
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.
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>>().