# Limited access to front matter to add image

**URL:** <https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539>\
**Category:** Help\
**Created:** [January 23, 2019, 4:57pm UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539 "2019-01-23T16:57:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![justinechacko](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/justinechacko/32/675_2.png) [@justinechacko](https://talk.jekyllrb.com/u/justinechacko)\
**Post date:** [January 23, 2019, 4:57pm UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539/1 "2019-01-23T16:57:42Z")

</div>

Suppose I have an image link in the post body like `![image](https://i.postimg.cc/26fT2WHW/1.png)`. I have access to front matter in such a way that I can add

```auto
---
...
image: here a default value, can't change
...
---

```

I need to place `https://i.postimg.cc/26fT2WHW/1.png` where the text appeared like `here a default value, can't change`. But I can’t use `https://i.postimg.cc/26fT2WHW/1.png` directly there. Any solution, please reply.

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [January 23, 2019, 5:21pm UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539/2 "2019-01-23T17:21:28Z")

</div>

I may misunderstand, but is this what you want to do?:

```auto
---
image: https://example.com/1.png
---

![image]({{page.image}})

```

---

<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:** [January 23, 2019, 5:41pm UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539/3 "2019-01-23T17:41:05Z")

</div>

1. the : is an illegal character in that context, enclose the whole line in quotes  
`image: "https://example.com/1.png"`

2. just put the path and filename in the front matter and add the https:// part in the code

---

<div class="post-metadata">

**Author:** ![justinechacko](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/justinechacko/32/675_2.png) [@justinechacko](https://talk.jekyllrb.com/u/justinechacko)\
**Post date:** [January 23, 2019, 5:54pm UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539/4 "2019-01-23T17:54:16Z")

</div>

@rdyar For some reason I can’t directly insert link `https://i.postimg.cc/26fT2WHW/1.png` in the front matter. I can Only put a default value(if available) that should be **same** for all posts.  
@chuckhoupt, No that’s not I meant.

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [January 23, 2019, 7:22pm UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539/5 "2019-01-23T19:22:56Z")

</div>

It sounds like you want to set a default for all posts? Jekyll has a few mechanisms for setting defaults. For example, [Front Matter Defaults](https://jekyllrb.com/docs/configuration/front-matter-defaults/) or [Liquid’s `defaults` filter](https://shopify.github.io/liquid/filters/default/).

---

<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:** [January 23, 2019, 9:21pm UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539/6 "2019-01-23T21:21:22Z")

</div>

it is not real clear what your issue is, can you give more info with a real example?

when you say you can’t put the url in the front matter is that cause you get an error? or?

---

<div class="post-metadata">

**Author:** ![justinechacko](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/justinechacko/32/675_2.png) [@justinechacko](https://talk.jekyllrb.com/u/justinechacko)\
**Post date:** [January 23, 2019, 10:47pm UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539/7 "2019-01-23T22:47:04Z")

</div>

@rdyar I am in a situation that I have no direct access to front matter of posts. I can preset a value in front matter of posts which will unique for all posts. I can’t put image url everytime, Is there a way to grab the image url from post body and access it in front matter by using a unique value (Some times liquid - I know liquid not allowed infront matter, may have workarounds). Then I can access it in post excerpt or somewhere in the index file by using {{post.image}} tag.  
@chuckhoupt You are near to that, any more suggestions

---

<div class="post-metadata">

**Author:** ![justinechacko](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/justinechacko/32/675_2.png) [@justinechacko](https://talk.jekyllrb.com/u/justinechacko)\
**Post date:** [January 24, 2019, 12:53am UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539/8 "2019-01-24T00:53:04Z")

</div>

Hi, I found a workaround, but with some problem. I used following code

```auto
{% assign foundImage = 0 %}
      {% assign images = post.content | split:"<img " %}
      {% for image in images %}
        {% if image contains 'src' %}

            {% if foundImage == 0 %}
                {% assign html = image | split:"/>" | first %}
                <img {{ html }} />
                {% assign foundImage = 1 %}
            {% endif %}
        {% endif %}
      {% endfor %}

```

It is working [here](https://news.justinechacko.in/sports/2018/02/25/file8.html), But [here](https://news.justinechacko.in/india/2018/02/25/file9.html) post containing `iframe` at first position it breaks the page.

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [January 24, 2019, 1:23pm UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539/9 "2019-01-24T13:23:17Z")

</div>

Possibly you could use the [Post Excerpts](https://jekyllrb.com/docs/posts/#post-excerpts) feature to isolate the part of the post with the image? But maybe that isn’t enough.

If I understand correctly, you’d like to have automatic access to the the `src` URL of the first image in every post – sort of an image-excerpt for posts? Although you can use a work-around in Liquid, I think a [custom plugin](https://jekyllrb.com/docs/plugins/) in Ruby might be a better route.

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [January 24, 2019, 2:43pm UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539/10 "2019-01-24T14:43:49Z")

</div>

> [@justinechacko](#):
>
> Is there a way to grab the image url from post body and access it in front matter by using a unique value

This is not possible with Vanilla Jekyll.  
Jekyll does not process the body first and then the front matter. The entire document is parsed in a single pass.

---

<div class="post-metadata">

**Author:** ![bpmottathai](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/bpmottathai/32/1434_2.png) [@bpmottathai](https://talk.jekyllrb.com/u/bpmottathai)\
**Post date:** [January 25, 2019, 6:24am UTC](https://talk.jekyllrb.com/t/limited-access-to-front-matter-to-add-image/2539/11 "2019-01-25T06:24:23Z")

</div>

Ok, thanks for the support
