Skip to content

Commit

Permalink
#2278 Improve getting started docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed May 31, 2023
1 parent f248f3c commit 1b45339
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions docs/v2/getting-started/a-post-archive.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ You can then loop over your posts with a [for-loop in Twig](https://twig.symfony
<ul>
{% endif %}
{{ include('pagination.twig') }}
{{ include('pagination.twig') }}
{% endblock %}
```

Expand All @@ -45,6 +45,9 @@ Your teaser could look like this. We used the markup for an [Inclusive Card](htt
<img
src="{{ post.thumbnail.src('medium') }}"
alt="{{ post.thumbnail.alt }}"
width="{{ post.thumbnail.width }}"
height="{{ post.thumbnail.height }}"
loading="lazy"
>
<h2>
Expand All @@ -71,7 +74,7 @@ There are two new things that you see here:

## Using custom queries

Sometimes you’ll want to use your own queries for archive pages or to display a list of posts in other places. For that, you can use `Timber::get_posts()`. Here’s an example for a more complex query, that selects posts that have certain movie genre and actor terms assigned. The parameters you use are the same as those for [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/).
Sometimes you’ll want to use your own queries for archive pages or to display a list of posts in other places. For that, you can use `Timber::get_posts()`. Here’s an example for a more complex query, that selects posts that have certain movie genres and actor terms assigned. The parameters you use are the same as those for [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/).

```php
$args = [
Expand Down Expand Up @@ -111,6 +114,7 @@ $post = $context['post'];
$context['related_posts'] = Timber::get_posts([
'post_type' => 'post',
'posts_per_page' => 3,
'no_found_rows' => true,
'orderby' => 'date',
'order' => 'DESC',
'post__not_in' => [$post->ID],
Expand Down
2 changes: 1 addition & 1 deletion docs/v2/getting-started/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ See how there’s no HTML in our PHP file? And do you see how we fetch the data

In Timber, we prepare a lot for you in the background, so you don’t have to remember function names like `get_the_title()`.

Most of Timber’s templates look like this:
Most Timber templates look like this:

**index.php**

Expand Down
6 changes: 3 additions & 3 deletions docs/v2/getting-started/template-inheritance-and-includes.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ For this introduction, let’s assume that the name of the page is "All about Ja
{% block headline %}
<header>
<h1 class="article-title">{{ post.title }}</h1>
<p role="doc-subtitle">{{ post.subtitle }}</h2>
<p role="doc-subtitle">{{ post.subtitle }}</p>
</header>
{% endblock %}
<p class="article-author"><span>By</span> {{ post.author.name }} <span>&bull;</span> {{ post.post_date }}</p>
<p class="article-author"><span>By</span> {{ post.author.name }} <span>&bull;</span> {{ post.date }}</p>
{{ post.content }}
</section>
Expand Down Expand Up @@ -141,7 +141,7 @@ So there are two big concepts going on here:
1. **Multiple Inheritance:** We’re extending **single.twig**, which itself extends **base.twig**. Thus we stay true to the [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) principle and don’t have very similar code between our two templates hanging around.
2. **Nested Blocks:** `{% block headline %}` is located inside `{% block content %}`. So while we’re replacing the headline, we get to keep all the other markup and variables found in the parent template.

What if you wanted to **add** something to the block as opposed to replace? In this case you can [`{{ parent() }}`](https://twig.symfony.com/doc/functions/parent.html) where the parent block’s content should go.
What if you wanted to **add** something to the block as opposed to replace? In this case you can use [`{{ parent() }}`](https://twig.symfony.com/doc/functions/parent.html) where the parent block’s content should go.

```twig
{% extends "single.twig" %}
Expand Down

0 comments on commit 1b45339

Please sign in to comment.