2017-12-18 314 views
1

我正在構建一個Jekyll站點,並希望在帖子顯示頁面上顯示feature-imgs。我以爲自己的Front方向正確,文件路徑正確,但由於某種原因,圖像仍然不顯示。未顯示帖子的功能圖片Jekyll

前面的問題

--- 
layout: post 
title: My Coding Journey 
feature-img: "/img/journey.png" 
--- 

我的圖片名爲IMG項目根文件夾中。

郵政佈局:

--- 
layout: post-header 
--- 
<article {% if page.feature-img %} class="feature-image"{% endif %}> 
    <section class="post-content">{{ content }}</section> 
</article> 

<!-- Disqus --> 
{% if site.theme_settings.disqus_shortname %} 
<div class="comments"> 
    {% include disqus.html %} 
</div> 
{% endif %} 

任何想法,爲什麼特徵圖像不工作。

+0

這是否解決您的問題'功能IMG: 「./img/journey.png」'?我在圖像路徑前添加了一段時間。 – Ivan86

+0

不,不過,謝謝。 – Joseph

+0

嘗試像這樣'feature-img:「./../ img/journey.png」'或這個'feature-img:「./../../ img/journey.png」' – Ivan86

回答

2

您需要一個img標記才能呈現圖像。

--- 
layout: post 
title: My Coding Journey 
feature-img: "/img/journey.png" 
--- 

,並在佈局...

<article> 
    {% if page.feature-img %} 
    <img class="feature-image" src={{ page.feature-img }} alt="Feature Image"/> 
    {% endif %} 
    <section class="post-content">{{ content }}</section> 
</article> 
+0

來自Jekyll https://jekyllrb.com/docs/frontmatter/ – Joseph

+0

他們在哪裏提到你可以使用'-'作爲變量的分隔符? – ashmaroli

+0

我繼續進行調整。仍然沒有變化。我誤解了你的建議。謝謝你。 – Joseph