0
votes

I'm using Timber for my Wordpress theme and for some time now I've noticed that Timber does not show the content of new pages created.

Here is an example of my structure:

I have a work.php page that contains the following context:

        $context = Timber::get_context();

$args = array(
    // Get post type project
    'post_type' => 'project',
    // Get all posts
    'posts_per_page' => -1,
    // Order by post date
    'orderby' => array(
        'date' => 'DESC'
    )
);

$context['post'] = new TimberPost();
$context['works'] = Timber::get_posts( $args );

Timber::render( 'page-work.twig', $context );

Then I have a "page-work.twig" page retrieves an include "inc-work.twig"

{% extends "base.twig" %}
{% block content %}
    {% include 'inc-work.twig' %}  
{% endblock %}

Here is the inc-work.twig include

<section class="l-homegrid lazy-scroll">
  {% for post in works %}
    {% if post.thumbnail %}
      <a href="{{post.link}}" class="l-basicgrid-work work">
        <article>
          <figure>
            <img data-src="{{post.get_thumbnail.src('full')|resize(800, 533)}}" alt="project {{post.title}}" class="lazy">
          </figure>
          <figcaption>
            <h2>{{ post.title }}</h2>
          </figcaption>
        </article>
      </a>
    {% endif %}
  {% endfor %}      
</section>

I feel that my code is correct. However, the Custom Content Type "Project" is not displayed. It's strange, because I use the structure without any problem for other pages of the same site ...

Any ideas?

Thank you!

1
What’s the slug of your Custom Post Type? Is it work or project? Are you sure that work.php is displayed? And did you realize that you’re rendering page-graphic.twig, but you list page-work.twig as the Twig view? - Gchtr
Thank you for your answer! The slug is "work". Page-graphic.twig was copy/paste error. I do use "page-work.twig" but it still don't work :-/ - filnug
Ok, so you use {% for post in works %} in your Twig file, but I don’t see where you add works to your context. You add graphics, though. Might this be the problem? - Gchtr
Sorry if I haven't read my code before to post. But online, the "work.php" file has : $context['post'] = new TimberPost(); $context['works'] = Timber::get_posts( $args ); Timber::render( 'page-work.twig', $context ); But anyway, nothing it is rendered... - filnug
Do you get any output if you use {{ dump(post) }} right after {% for post in works %}? - Gchtr

1 Answers

0
votes

Is the issue not that you are passing $context['post']?

Have you tried just changing the code to

{% for work in works %}
    ...
{% endfor %} 

Just to make sure that there is no conflicting variables in the context?