سؤال

Question: With Jekyll is it possible to display part of a markdown file in a template file?

I would want to do this in order to avoid using div's in my markdown, I have some elements that need styling and if you put div's in markdown then anything in them will not be marked down(if you add markdown="1" it just adds a grey box around the text). So to get around this I want to capture some text like so:

{% capture workshops %}
    ![Suitcase]({{ site.url }}/img/icons/suitcase.png)
    **Proffesional Workshops**
    Brief description of workshops, more detailed description 
    of workshops will go on seperate dedicated page.
{% endcapture %}

and then somehow put this markdown in the layout page maybe like this?

<div class="feature">
    {{ page.workshops }}
</div>

Is this possible? or is there a better way of getting around using div's

هل كانت مفيدة؟

المحلول

You could use excerpts.

Quote from the link:

Each post automatically takes the first block of text, from the beginning of the content to the first occurrence of excerpt_separator, and sets it as the post.excerpt. Take the above example of an index of posts. Perhaps you want to include a little hint about the post’s content by adding the first paragraph of each of your posts:

<ul>
  {% for post in site.posts %}
    <li>
      <a href="{{ post.url }}">{{ post.title }}</a>
      <p>{{ post.excerpt }}</p>
    </li>
  {% endfor %}
</ul>

I'm not sure if you need this for blog posts or for actual pages.
The above quote is from the documentation about blog posts, but apparently every page has the .excerpt property, according to the documentation about variables.
(I didn't try it with a page, though)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top