Partials

Partials in the context of theme-redone, are reusable pieces of code that live inside [theme-root]/views/parts/ directory.

To include them in the template we are working with, we would use the latte’s include, along with the tr_part('partial-name') helper function. So, if the partial’s name is ‘partial-name’, we would include it like so: {include tr_part('partial-name')}.


Example Use Case

In the screenshot below, we have two files open. The one on the left-hand side is the partial file called post-card.latte and as described above, it lives in the [theme-root]/views/parts/ directory.

In the file on the right-hand side, we are inside a custom WP_Query loop, from which we are including the post-card partial on line 19.

theme-redone partials use-case example

In the example above we are not using any arguments along with the include, but it’s worth mentioning that is, of course, possible with latte, and allows us to work with dynamic partials.

Here’s a quick example.

Here, we are including a partial called hero, and passing two arguments: headline, and background_dark.
Feel free to visit latte’s official documentation website to learn more.

{include
  tr_part('hero'),
  headline: $example_headline,
  background_dark: true
}
Join Our Newsletter

To get updates about Theme Redone