wordpresstwigtimber

Ouput ACF Color Picker Field Type from categories


I want to get the color of a category. In ACF I have created a color picker field type, which I can then adjust via Posts > Categories > Category.

How can I get the output of an ACF color picker field type through Timber?

I just can't get it done. What am I doing wrong?

This is what I have now.

Timber controller (single.php)

$context         = Timber::context();
$timber_post     = Timber::query_post();
$context['post'] = $timber_post;

$context['categories']  = get_terms(array('taxonomy' => 'category'));
$context['tags']        = get_terms(array('taxonomy' => 'post_tag'));

if ( post_password_required( $timber_post->ID ) ) {
    Timber::render( 'single-password.twig', $context );
} else {
    Timber::render( array(
    'posts/' . $timber_post->ID . '.twig',
    'posts/' . $timber_post->post_type . '.twig',
    'posts/' . $timber_post->slug . '.twig',
    'single.twig' ),
    $context );
}

Twig file (post.twig)

<div class="badge bg-[{{ category.meta('category_color') }}] mb-5">

  {{ post.category }}

</div>

Solution

  • It looks like you're missing the post in the variable inside the class. It should probably be {{ post.category.meta('category_color') }}.