Skip to main content

contexts/post

The post context.

Attributes

Name Type Description
post dict A dictionary containing data about the post.
post.authors list A list of the post’s authors.
post.authors[].avatar str The author’s avatar URL.
post.authors[].bio str The author’s bio.
post.authors[].id str The author’s unique id.
post.authors[].name str The author’s name.
post.content str The post’s content.
post.created_at datetime The post’s date and time it was created.
post.excerpt str The post’s excerpt.
post.has_next_post bool Whether there is a next post in accordance with the chronological order of the blog.
post.has_prev_post bool Whether there is a previous post in accordance with the chronological order of the blog.
post.id str The post’s unique id.
post.images list A list of the post’s images. Note that these are all the images uploaded to the post in the Typed Dashboard and not just the subset of which are included in the post’s content.
post.images[].id str The image’s unique id.
post.images[].url str The image’s absolute URL.
post.linked_url str The post’s linked URL.
post.next_post dict A dictionary containing data about the next post in accordance with the chronological order of the blog.
post.prev_post dict A dictionary containing data about the previous post in accordance with the chronological order of the blog.
post.published_at datetime The post’s date and time it was published.
post.tags list A list of the post’s tags.
post.tags[].id str The tag’s unique id.
post.tags[].title str The tag’s title.
post.tags[].url str The tag’s URL.
post.title str The post’s title.
post.updated_at datetime The post’s date and time it was last updated.
post.url str The post’s URL.

Description

The post context is used when rendering the post template.

The post.next_post and post.prev_post attributes are dictionaries containing data about the next and previous posts in accordance with the chronological order of the blog. However these attributes can be None if there are no appropriate posts for each. You should therefore use post.has_next_post and post.has_prev_post before attempting to access them. The set of attributes for each of these posts are the same as post, excluding post.has_next_post, post.has_prev_post, post.next_post and post.prev_post.

Examples

{
  'post': {
    'authors': [
      {
        'avatar': 'https://avatars.typed.com/d07eed0c-9185-4fb8-8cc1-e5cb19a44e16/avatar.jpg',
        'bio': '<p>I make <strong>amazing</strong> coffee.</p>',
        'id': '46695d0b-6d4a-447e-a740-a1dc06e80baf',
        'name': 'The Coffee Master'
      }
    ],
    'content': '<p>Some people are lactose-intolerant and can’t drink milk. If that’s you, then here’s the 5 best alternatives to classic moo-moo milk.</p><ol><li><a href="http://www.bonsoy.com">Bonsoy</a></li><li>Home-made Almond Milk</li><li><a href="http://www.oatly.com/products/international/foamable/">Oatly Foamable</a></li><li>Barista style Alpro (it’s pretty shoddy, but it’ll do in a pinch)</li><li>Go for an espresso instead.</li></ol><p>That’s it, if you have any suggestions please get in touch.</p>',
    'created_at': datetime(2015, 10, 26, 10, 39, 51, tzinfo=<DstTzInfo 'Europe/Paris' CET+1:00:00 STD>),
    'excerpt': '<p>Some people are lactose-intolerant and can’t drink milk. If that’s you, then here’s the 5 best alternatives to classic moo-moo milk.</p>',
    'has_next_post': False,
    'has_prev_post': False,
    'id': 'dd852700-5c89-479f-b695-874137225872',
    'images': [
      {
        'id': 'ebcc4cb4-728d-4d85-8acb-c07877c9d159',
        'url': 'https://images.typed.com/ebcc4cb4-728d-4d85-8acb-c07877c9d159/image.jpg'
      }
    ],
    'linked_url': 'http://www.bonsoy.com',
    'next_post': None,
    'prev_post': None,
    'published_at': datetime(2015, 10, 26, 12, 00, tzinfo=<DstTzInfo 'Europe/Paris' CET+1:00:00 STD>),
    'tags': [
      {
        'id': '569b38ef-61c9-43f5-a82c-6cd6edaea0aa',
        'title': 'Review',
        'url': '/tags/review'
      }
    ],
    'title': 'Top 5 Alternatives to Milk in Coffee',
    'updated_at': datetime(2015, 10, 26, 11, 18, 24, tzinfo=<DstTzInfo 'Europe/Paris' CET+1:00:00 STD>),
    'url': '/blog/top-5-alternatives-to-milk-in-coffee'
  }
}

Next/Prev Post

As mentioned above the set of attributes for each of post.next_post and post.prev_post are mostly the same as post. The following example demonstrates how to display the title of the next post.

{% if post.has_next_post %}
  <h1>{{ post.next_post.title }}</h1>
{% endif %}