Skip to content
Filip Chalupa edited this page Oct 30, 2018 · 8 revisions

Mostly based on Latte templating and macros


{set $x = 'y'|filters}

Like {var $x = 'y'} macro, but set executes filters and assigns the result to the variable. var macro simply ignores filters.

Since the Latte 2.4 similar thing is possible like {var $x = ('y'|filters)} - just wrap the expression in parentheses and there it is.

{var $name = 'Žlutá liška'}

{var $slug = $name | webalize}
// filter is ignored
// $slug = 'Žlutá liška'

{var $slug = ($name | webalize)}
// $slug = 'zluta-liska'

{set $slug = $name | webalize}
// $slug = 'zluta-liska'

{each [$wp_query] [as $Post]}

Makes loop through WP_Query or simple array, by default it takes the main global $wp_query, and in every iteration you get $Post object.

// uses default global $wp_query
{each}
  {dump $Post}
{/each}

// works with regular arrays
{each [1, 2, 3] as $x}
  {dump $x}
{/each}

// uses default global $wp_query, but assigns the item to defined variable
{each as $myPost}
  {dump $myPost}
{/each}

{var $customQuery = new WP_Query('post_type=event')}
{each $customQuery}
  {dump $Post}
{/each}

{each $customQuery as $myPost}
  {dump $myPost}
{/each}

{loop [$wp_query]} (but macro {each} is better)

Makes loop through WP_Query, by default it takes the main global $wp_query, and in every iteration you get $Post object.

{loop}
  {dump $Post}
{/loop}

{var $customQuery = new WP_Query('post_type=event')}
{loop $customQuery}
  {dump $Post}
{/loop}

{repeat [$count=5]}

Just repeats the same code $count times (5 by default).

// five times dumps `rand()`.
{repeat}
  {dump rand()}
{/repeat}

// ten times dumps `rand()`.
{repeat 10}
  {dump rand()}
{/repeat}

// randomly between the two arguments (min 1, max 100) dumps `rand()`.
{repeat 1, 100}
  {dump rand()}
{/repeat}

{shape $name}

Renders shape. E.g. {shape mangoweb} renders manGoweb logo.