# Different Content on Index Page and on the Post Page

**URL:** <https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441>\
**Category:** Uncategorized\
**Created:** [May 16, 2020, 6:57pm UTC](https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441 "2020-05-16T18:57:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Royi](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/royi/32/1630_2.png) [@Royi](https://talk.jekyllrb.com/u/Royi)\
**Post date:** [May 16, 2020, 6:57pm UTC](https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441/1 "2020-05-16T18:57:34Z")

</div>

I have posts which includes the following YMAL:

```auto
---
title: 'Some Title'
date: 2017-09-30
author: Some Name
layout: post
class: news
---

```

Now, I want to have different content to the page when used form different places in the site.

For instance, let’s assume this is the post content (In the `_posts` folder):

```auto
{% if page.layout != "post" %}
This is some uninteresting content.
{% endif %}

{% if page.tag == "post" %}
This is a different uninteresting content.
{% endif %}

This is for all pages

```

So what I’m after is the page to have different beginning if it is used no as a post. For instance when it is used in other page.

In my specific case, I want the content of the `page.layout != "post"` tag to be displayed in the index page where I use `pagination`.

Yet it seems _Jekyll_ is doing only single pass to generate the HTML content.  
Is there a way to do so?

I know the tricks to use excerpts. But in my case I want to have content on the pagination page which I don’t want to be used at all on the post page.

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [May 17, 2020, 1:22am UTC](https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441/2 "2020-05-17T01:22:30Z")

</div>

i don’t understand - can you give specific examples of which page you want to do what?

> [@Royi](#):
>
> In my specific case, I want the content of the `page.layout != "post"` tag to be displayed in the index page where I use `pagination` .

what index page? there is only one home/root/index page. Is that the page you mean?

It isn’t clear why you wouldn’t just change the _content_ of the page in question rather than looping thru and checking the layout in use in the layout file?

---

<div class="post-metadata">

**Author:** ![Royi](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/royi/32/1630_2.png) [@Royi](https://talk.jekyllrb.com/u/Royi)\
**Post date:** [May 17, 2020, 11:21am UTC](https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441/3 "2020-05-17T11:21:32Z")

</div>

I tried explaining it also in [https://stackoverflow.com/questions/61843730](https://stackoverflow.com/questions/61843730).  
Tell me if it is more clear, than I will edit the question to match.

The idea is like we don’t code twice I don’t want to write things twice.  
The _problem_ is equivalent to scoping, I’d like the page to be processed as post in the post and as something else in the index page.

The index page is the page showing all posts (Excerpt of each).

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [May 17, 2020, 4:11pm UTC](https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441/4 "2020-05-17T16:11:51Z")

</div>

right - the page is only going to be processed once - it isn’t going to be able to put stuff on a different page if I understand what you want.

Would front matter work? from your example I think it would work no problem just different to write.

---

<div class="post-metadata">

**Author:** ![Royi](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/royi/32/1630_2.png) [@Royi](https://talk.jekyllrb.com/u/Royi)\
**Post date:** [May 17, 2020, 5:42pm UTC](https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441/5 "2020-05-17T17:42:37Z")

</div>

Hi Ron,

I suspected I’d have to do it that way.  
The question is, how can I write many sentences in the excerpt? How can I add an image using the Excerpt?

Also, what exactly is taken from the page in case no `excerpt` is defined? Is it the HMTL generated form the pass? Is it the RAW text in the page?

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [May 17, 2020, 11:52pm UTC](https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441/6 "2020-05-17T23:52:43Z")

</div>

Check [Jekyll’s docs on excerpts](https://jekyllrb.com/docs/posts/#post-excerpts). They can be configured to automatically create using the first paragraph, adding a separation tag, or via front matter e.g. `excerpt: My custom excerpt.`

RE: reusing content. I think you want to investigate using [Jekyll includes](https://jekyllrb.com/docs/includes/) and breaking up your page content instead of trying to jam it all into a single file that is used in different contexts.

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [May 18, 2020, 3:13am UTC](https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441/7 "2020-05-18T03:13:30Z")

</div>

your example doesn’t really have much info on what you are actually trying to do (and maybe why) - like mm says includes are very powerful and so are data files. All depends on what it is you are trying to do.

It is usually nice to have super minimal example, but other times an actual real world example is more helpful.

---

<div class="post-metadata">

**Author:** ![Royi](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/royi/32/1630_2.png) [@Royi](https://talk.jekyllrb.com/u/Royi)\
**Post date:** [May 18, 2020, 5:45am UTC](https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441/8 "2020-05-18T05:45:55Z")

</div>

If you look at the link I posted you’d see I am aware of `excerpt` and `excerpt_separator` yet they won’t solve the issue I want.

I also use `include` yet I am not sure how they will solve the problem here as the `include` will be parsed on both.

Basically what I am after is a way to mimic parsing the page in 2 different scopes. One as a post and the other as part of the index page. Yet, according to @rdyar it can’t be done. So the question is if there is a trick to do so.

@rdyar, If you want a context of what I do, think about the case I want an image to be shown in the post but not on the index and a sentence of something like `Here we go again` which I want on the index but not on the page.

By the way, If `excerpt` allows using Markdown and use multi line text, it would be great.

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [May 18, 2020, 11:30am UTC](https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441/9 "2020-05-18T11:30:27Z")

</div>

`excerpt` is like any other front matter variable… it can support Markdown or multi line text if you set it up that way. There’s nothing preventing you from doing:

```auto
excerpt: "This is my **Markdown** string."

```

Or

```auto
excerpt: |
  This is my mult line **Markdown** string.

  With another paragraph.

```

And then in your layout or include doing `{{ page.excerpt | markdownify }}`

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [May 18, 2020, 4:04pm UTC](https://talk.jekyllrb.com/t/different-content-on-index-page-and-on-the-post-page/4441/10 "2020-05-18T16:04:16Z")

</div>

> [@Royi](#):
>
> I also use `include` yet I am not sure how they will solve the problem here as the `include` will be parsed on both.

then use different layouts? with a for loop you can loop thru posts and put their info where ever you want - but the post itself as a single page is only once. The for loop could do the same thing but would be putting all the posts (unless excluded) on the same page. Sure, maybe the layout file would have a duplicate header and footer and what not, but for me those are inlcudes as well so they aren’t really dupes.

Your example of an image and a line of text seems to me could very easily be done in front matter with different layouts - the home page has one layout, all the posts get the other.
