Skip to content

Instantly share code, notes, and snippets.

@geoffyuen
Last active February 23, 2021 04:32
Show Gist options
  • Select an option

  • Save geoffyuen/abc8074cd94423655ae1e499cb29a75e to your computer and use it in GitHub Desktop.

Select an option

Save geoffyuen/abc8074cd94423655ae1e499cb29a75e to your computer and use it in GitHub Desktop.
Timber Cheatsheet

Timber Cheatsheet

Srcset images

<img src="{{ fn('wp_get_attachment_image_url', post.thumbnail.id, 'medium') }}" 
  srcset="{{ fn('wp_get_attachment_image_srcset', post.thumbnail.id, 'medium' ) }}"
  sizes="(max-width: 1024px) 100vw, 1024px" 
  alt="Post thumbnail">

Show if admin or localhost

Great for debugging. Uses the collapsable details element.

{% if user.wp_capabilities.administrator or site.url|split('//localhost')|length %}
<details>
	<summary>Dump</summary>
	{{ dump(post) }}
</details>
{% endif %}

ACF checkbox

{{ if post.a_checkbox is empty }}
	// Do stuff if unchecked or does not exist
{{ else }}
	// Do stuff if checked
{{ endif }}

Get all Terms

$context['the_categories'] = Timber::get_terms('my_category');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment