Different Content on Index Page and on the Post Page

I have posts which includes the following YMAL:

---
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):

{% 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.

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

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?

I tried explaining it also in 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).

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.

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?

Check Jekyll’s docs on 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 and breaking up your page content instead of trying to jam it all into a single file that is used in different contexts.

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.

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.

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:

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

Or

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

  With another paragraph.

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

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.