This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Daniel81
Daniel81

In the Markup Guide it states that "October extends Twig engine with a number of functions, tags, filters and variables.", does anyone know where these can be found?

For example, I've used the {{ product.image.thumb(200, auto) }} function on an outputted image to create a 200px wide thumbnail, but can't find anywhere in the docs etc where this is defined, I think I just stumbled across it by accident and I'm assuming it references the getThumb() PHP function, but can't find where this is all linked in the docs.

I've looked in the modules/cms/twig/Extension.php file where there are a number of extensions/functions defined, but not the thumb function above, so I'm just wondering if there are any other functions like crop, scale etc for images, along with maybe some other functions for other elements defined elsewhere?

Last updated

Daniel81
Daniel81

PS, this is what get outputted into the rendered twig_template:

echo twig_escape_filter($this->env, $this->getAttribute($this->getAttribute((isset($context["product"]) ? $context["product"] : null), "image"), "thumb", array(0 => 200, 1 => (isset($context["auto"]) ? $context["auto"] : null)), "method"), "html", null, true);

if it helps anyone? You can see the thumb get outputted as a method with the array of options.

Last updated

daftspunky
daftspunky

The most important thing to learn about Twig is how it accesses the PHP layer. For convenience sake {{ foo.bar }} does the following:

  1. check if foo is an array and bar a valid element
  2. if not, and if foo is an object, check that bar is a valid property
  3. if not, and if foo is an object, check that bar is a valid method (even if bar is the constructor - use __construct() instead)
  4. if not, and if foo is an object, check that getBar is a valid method
  5. if not, and if foo is an object, check that isBar is a valid method
  6. if not, return a null value.
adis.osmonov
adis.osmonov

Excellent!

Last updated

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.