site/docs/includes/index.html in jekyll-docs-3.5.2 vs site/docs/includes/index.html in jekyll-docs-3.6.0
- old
+ new
@@ -2,32 +2,32 @@
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
- <meta name="generator" content="Jekyll v3.5.2">
+ <meta name="generator" content="Jekyll v3.6.0">
<link type="application/atom+xml" rel="alternate" href="https://jekyllrb.com/feed.xml" title="Jekyll • Simple, blog-aware, static sites">
<link rel="alternate" type="application/atom+xml" title="Recent commits to Jekyll’s master branch" href="https://github.com/jekyll/jekyll/commits/master.atom">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic,900">
<link rel="stylesheet" href="/css/screen.css">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
- <!-- Begin Jekyll SEO tag v2.2.3 -->
+ <!-- Begin Jekyll SEO tag v2.3.0 -->
<title>Includes | Jekyll • Simple, blog-aware, static sites</title>
<meta property="og:title" content="Includes">
<meta property="og:locale" content="en_US">
<meta name="description" content="The include tag allows you to include the content from another file stored in the _includes folder:">
<meta property="og:description" content="The include tag allows you to include the content from another file stored in the _includes folder:">
<link rel="canonical" href="https://jekyllrb.com/docs/includes/">
<meta property="og:url" content="https://jekyllrb.com/docs/includes/">
<meta property="og:site_name" content="Jekyll • Simple, blog-aware, static sites">
<meta property="og:type" content="article">
-<meta property="article:published_time" content="2017-08-12T13:36:54-07:00">
+<meta property="article:published_time" content="2017-10-24T08:07:43-07:00">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@jekyllrb">
<meta name="google-site-verification" content="onQcXpAvtHBrUI5LlroHNE_FP0b2qvFyPq7VZw36iEY">
<script type="application/ld+json">
-{"@context":"http://schema.org","@type":"BlogPosting","headline":"Includes","datePublished":"2017-08-12T13:36:54-07:00","dateModified":"2017-08-12T13:36:54-07:00","description":"The include tag allows you to include the content from another file stored in the _includes folder:","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"https://jekyllrb.com/img/logo-2x.png"}},"mainEntityOfPage":{"@type":"WebPage","@id":"https://jekyllrb.com/docs/includes/"},"url":"https://jekyllrb.com/docs/includes/"}</script>
+{"name":null,"description":"The include tag allows you to include the content from another file stored in the _includes folder:","url":"https://jekyllrb.com/docs/includes/","headline":"Includes","dateModified":"2017-10-24T08:07:43-07:00","datePublished":"2017-10-24T08:07:43-07:00","sameAs":null,"@type":"BlogPosting","author":null,"image":null,"publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"https://jekyllrb.com/img/logo-2x.png"}},"mainEntityOfPage":{"@type":"WebPage","@id":"https://jekyllrb.com/docs/includes/"},"@context":"http://schema.org"}</script>
<!-- End Jekyll SEO tag -->
<!--[if lt IE 9]>
<script src="/js/html5shiv.min.js"></script>
<script src="/js/respond.min.js"></script>
@@ -287,25 +287,21 @@
<a href="https://github.com/jekyll/jekyll/edit/master/docs/_docs/includes.md"><i class="fa fa-pencil"></i> Improve this page</a>
</div>
<h1>Includes</h1>
<p>The <code class="highlighter-rouge">include</code> tag allows you to include the content from another file stored in the <code class="highlighter-rouge">_includes</code> folder:</p>
-<div class="language-liquid highlighter-rouge">
-<pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="w"> </span><span class="na">footer</span><span class="p">.</span><span class="na">html</span><span class="w"> </span><span class="p">%}</span>
-</code></pre>
-</div>
+<div class="language-liquid highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="w"> </span><span class="na">footer</span><span class="p">.</span><span class="na">html</span><span class="w"> </span><span class="p">%}</span>
+</code></pre></div></div>
<p>Jekyll will look for the referenced file (in this case, <code class="highlighter-rouge">footer.html</code>) in the <code class="highlighter-rouge">_includes</code> directory at the root of your source directory and insert its contents.</p>
<h3 id="including-files-relative-to-another-file">Including files relative to another file</h3>
<p>You can choose to include file fragments relative to the current file by using the <code class="highlighter-rouge">include_relative</code> tag:</p>
-<div class="language-liquid highlighter-rouge">
-<pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="na">_relative somedir/footer</span><span class="p">.</span><span class="na">html</span><span class="w"> </span><span class="p">%}</span>
-</code></pre>
-</div>
+<div class="language-liquid highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="na">_relative somedir/footer</span><span class="p">.</span><span class="na">html</span><span class="w"> </span><span class="p">%}</span>
+</code></pre></div></div>
<p>You won’t need to place your included content within the <code class="highlighter-rouge">_includes</code> directory. Instead,
the inclusion is specifically relative to the file where the tag is being used. For example,
if <code class="highlighter-rouge">_posts/2014-09-03-my-file.markdown</code> uses the <code class="highlighter-rouge">include_relative</code> tag, the included file
must be within the <code class="highlighter-rouge">_posts</code> directory or one of its subdirectories.</p>
@@ -317,73 +313,61 @@
<h3 id="using-variables-names-for-the-include-file">Using variables names for the include file</h3>
<p>The name of the file you want to embed can be specified as a variable instead of an actual file name. For example, suppose you defined a variable in your page’s front matter like this:</p>
-<div class="language-yaml highlighter-rouge">
-<pre class="highlight"><code><span class="nn">---</span>
-<span class="s">title</span><span class="pi">:</span> <span class="s">My page</span>
-<span class="s">my_variable</span><span class="pi">:</span> <span class="s">footer_company_a.html</span>
+<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nn">---</span>
+<span class="na">title</span><span class="pi">:</span> <span class="s">My page</span>
+<span class="na">my_variable</span><span class="pi">:</span> <span class="s">footer_company_a.html</span>
<span class="nn">---</span>
-</code></pre>
-</div>
+</code></pre></div></div>
<p>You could then reference that variable in your include:</p>
-<div class="language-liquid highlighter-rouge">
-<pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="w"> </span>{{<span class="w"> </span><span class="nv">page</span><span class="p">.</span><span class="nv">my_variable</span><span class="w"> </span>}}<span class="w"> </span><span class="p">%}</span>
-</code></pre>
-</div>
+<div class="language-liquid highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="w"> </span>{{<span class="w"> </span><span class="nv">page</span><span class="p">.</span><span class="nv">my_variable</span><span class="w"> </span>}}<span class="w"> </span><span class="p">%}</span>
+</code></pre></div></div>
<p>In this example, the include would insert the file <code class="highlighter-rouge">footer_company_a.html</code> from the <code class="highlighter-rouge">_includes/footer_company_a.html</code> directory.</p>
<h3 id="passing-parameters-to-includes">Passing parameters to includes</h3>
<p>You can also pass parameters to an include. For example, suppose you have a file called <code class="highlighter-rouge">note.html</code> in your <code class="highlighter-rouge">_includes</code> folder that contains this formatting:</p>
-<div class="language-liquid highlighter-rouge">
-<pre class="highlight"><code><div markdown="span" class="alert alert-info" role="alert">
+<div class="language-liquid highlighter-rouge"><div class="highlight"><pre class="highlight"><code><div markdown="span" class="alert alert-info" role="alert">
<i class="fa fa-info-circle"></i> <b>Note:</b>
<span class="p">{{</span><span class="w"> </span><span class="nv">include</span><span class="p">.</span><span class="nv">content</span><span class="w"> </span><span class="p">}}</span>
</div>
-</code></pre>
-</div>
+</code></pre></div></div>
-<p>The <code class="highlighter-rouge"><span class="p">{</span><span class="err">{</span><span class="w"> </span><span class="err">include.content</span><span class="w"> </span><span class="p">}</span><span class="err">}</span></code> is a parameter that gets populated when you call the include and specify a value for that parameter, like this:</p>
+<p>The <code class="highlighter-rouge">{{ include.content }}</code> is a parameter that gets populated when you call the include and specify a value for that parameter, like this:</p>
-<div class="language-liquid highlighter-rouge">
-<pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="w"> </span><span class="na">note</span><span class="p">.</span><span class="na">html</span><span class="w"> </span><span class="na">content</span><span class="o">=</span><span class="s2">"This is my sample note."</span><span class="w"> </span><span class="p">%}</span>
-</code></pre>
-</div>
+<div class="language-liquid highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="w"> </span><span class="na">note</span><span class="p">.</span><span class="na">html</span><span class="w"> </span><span class="na">content</span><span class="o">=</span><span class="s2">"This is my sample note."</span><span class="w"> </span><span class="p">%}</span>
+</code></pre></div></div>
-<p>The value of <code class="highlighter-rouge">content</code> (which is <code class="highlighter-rouge">This is my sample note</code>) will be inserted into the <code class="highlighter-rouge"><span class="p">{</span><span class="err">{</span><span class="w"> </span><span class="err">include.content</span><span class="w"> </span><span class="p">}</span><span class="err">}</span></code> parameter.</p>
+<p>The value of <code class="highlighter-rouge">content</code> (which is <code class="highlighter-rouge">This is my sample note</code>) will be inserted into the <code class="highlighter-rouge">{{ include.content }}</code> parameter.</p>
<p>Passing parameters to includes is especially helpful when you want to hide away complex formatting from your Markdown content.</p>
<p>For example, suppose you have a special image syntax with complex formatting, and you don’t want your authors to remember the complex formatting. As a result, you decide to simplify the formatting by using an include with parameters. Here’s an example of the special image syntax you might want to populate with an include:</p>
-<div class="language-html highlighter-rouge">
-<pre class="highlight"><code><span class="nt"><figure></span>
+<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><figure></span>
<span class="nt"><a</span> <span class="na">href=</span><span class="s">"http://jekyllrb.com"</span><span class="nt">></span>
<span class="nt"><img</span> <span class="na">src=</span><span class="s">"logo.png"</span> <span class="na">style=</span><span class="s">"max-width: 200px;"</span>
<span class="na">alt=</span><span class="s">"Jekyll logo"</span> <span class="nt">/></span>
<span class="nt"><figcaption></span>This is the Jekyll logo<span class="nt"></figcaption></span>
<span class="nt"></figure></span>
-</code></pre>
-</div>
+</code></pre></div></div>
<p>You could templatize this content in your include and make each value available as a parameter, like this:</p>
-<div class="language-liquid highlighter-rouge">
-<pre class="highlight"><code><figure>
+<div class="language-liquid highlighter-rouge"><div class="highlight"><pre class="highlight"><code><figure>
<a href="<span class="p">{{</span><span class="w"> </span><span class="nv">include</span><span class="p">.</span><span class="nv">url</span><span class="w"> </span><span class="p">}}</span>">
<img src="<span class="p">{{</span><span class="w"> </span><span class="nv">include</span><span class="p">.</span><span class="nv">file</span><span class="w"> </span><span class="p">}}</span>" style="max-width: <span class="p">{{</span><span class="w"> </span><span class="nv">include</span><span class="p">.</span><span class="nv">max</span><span class="err">-</span><span class="nv">width</span><span class="w"> </span><span class="p">}}</span>;"
alt="<span class="p">{{</span><span class="w"> </span><span class="nv">include</span><span class="p">.</span><span class="nv">alt</span><span class="w"> </span><span class="p">}}</span>"/>
<figcaption><span class="p">{{</span><span class="w"> </span><span class="nv">include</span><span class="p">.</span><span class="nv">caption</span><span class="w"> </span><span class="p">}}</span></figcaption>
</figure>
-</code></pre>
-</div>
+</code></pre></div></div>
<p>This include contains 5 parameters:</p>
<ul>
<li><code class="highlighter-rouge">url</code></li>
@@ -393,77 +377,65 @@
<li><code class="highlighter-rouge">caption</code></li>
</ul>
<p>Here’s an example that passes all the parameters to this include (the include file is named <code class="highlighter-rouge">image.html</code>):</p>
-<div class="language-liquid highlighter-rouge">
-<pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="w"> </span><span class="na">image</span><span class="p">.</span><span class="na">html</span><span class="w"> </span><span class="na">url</span><span class="o">=</span><span class="s2">"http://jekyllrb.com"</span><span class="err">
+<div class="language-liquid highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="w"> </span><span class="na">image</span><span class="p">.</span><span class="na">html</span><span class="w"> </span><span class="na">url</span><span class="o">=</span><span class="s2">"http://jekyllrb.com"</span><span class="err">
</span><span class="na">max-width</span><span class="o">=</span><span class="s2">"200px"</span><span class="w"> </span><span class="na">file</span><span class="o">=</span><span class="s2">"logo.png"</span><span class="w"> </span><span class="na">alt</span><span class="o">=</span><span class="s2">"Jekyll logo"</span><span class="err">
</span><span class="na">caption</span><span class="o">=</span><span class="s2">"This is the Jekyll logo."</span><span class="w"> </span><span class="p">%}</span>
-</code></pre>
-</div>
+</code></pre></div></div>
<p>The result is the original HTML code shown earlier.</p>
<p>To safeguard situations where users don’t supply a value for the parameter, you can use <a href="https://help.shopify.com/themes/liquid/filters/additional-filters#default">Liquid’s default filter</a>.</p>
<p>Overall, you can create includes that act as templates for a variety of uses — inserting audio or video clips, alerts, special formatting, and more. However, note that you should avoid using too many includes, as this will slow down the build time of your site. For example, don’t use includes every time you insert an image. (The above technique shows a use case for special images.)</p>
<h3 id="passing-parameter-variables-to-includes">Passing parameter variables to includes</h3>
-<p>Suppose the parameter you want to pass to the include is a variable rather than a string. For example, you might be using <code class="highlighter-rouge"><span class="p">{</span><span class="err">{</span><span class="w"> </span><span class="err">site.product_name</span><span class="w"> </span><span class="p">}</span><span class="err">}</span></code> to refer to every instance of your product rather than the actual hard-coded name. (In this case, your <code class="highlighter-rouge">_config.yml</code> file would have a key called <code class="highlighter-rouge">product_name</code> with a value of your product’s name.)</p>
+<p>Suppose the parameter you want to pass to the include is a variable rather than a string. For example, you might be using <code class="highlighter-rouge">{{ site.product_name }}</code> to refer to every instance of your product rather than the actual hard-coded name. (In this case, your <code class="highlighter-rouge">_config.yml</code> file would have a key called <code class="highlighter-rouge">product_name</code> with a value of your product’s name.)</p>
<p>The string you pass to your include parameter can’t contain curly braces. For example, you can’t pass a parameter that contains this: <code class="highlighter-rouge">"The latest version of {{ site.product_name }} is now available."</code></p>
<p>If you want to include this variable in your parameter that you pass to an include, you need to store the entire parameter as a variable before passing it to the include. You can use <code class="highlighter-rouge">capture</code> tags to create the variable:</p>
-<div class="language-liquid highlighter-rouge">
-<pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">capture</span><span class="w"> </span><span class="na">download_note</span><span class="w"> </span><span class="p">%}</span>The latest version of
+<div class="language-liquid highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">capture</span><span class="w"> </span><span class="na">download_note</span><span class="w"> </span><span class="p">%}</span>The latest version of
<span class="p">{{</span><span class="w"> </span><span class="nv">site</span><span class="p">.</span><span class="nv">product_name</span><span class="w"> </span><span class="p">}}</span> is now available.<span class="p">{%</span><span class="w"> </span><span class="nt">endcapture</span><span class="w"> </span><span class="p">%}</span>
-</code></pre>
-</div>
+</code></pre></div></div>
<p>Then pass this captured variable into the parameter for the include. Omit the quotation marks around the parameter content because it’s no longer a string (it’s a variable):</p>
-<div class="language-liquid highlighter-rouge">
-<pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="w"> </span><span class="na">note</span><span class="p">.</span><span class="na">html</span><span class="w"> </span><span class="na">content</span><span class="o">=</span><span class="nv">download_note</span><span class="w"> </span><span class="p">%}</span>
-</code></pre>
-</div>
+<div class="language-liquid highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">include</span><span class="w"> </span><span class="na">note</span><span class="p">.</span><span class="na">html</span><span class="w"> </span><span class="na">content</span><span class="o">=</span><span class="nv">download_note</span><span class="w"> </span><span class="p">%}</span>
+</code></pre></div></div>
<h3 id="passing-references-to-yaml-files-as-parameter-values">Passing references to YAML files as parameter values</h3>
<p>Instead of passing string variables to the include, you can pass a reference to a YAML data file stored in the <code class="highlighter-rouge">_data</code> folder.</p>
<p>Here’s an example. In the <code class="highlighter-rouge">_data</code> folder, suppose you have a YAML file called <code class="highlighter-rouge">profiles.yml</code>. Its content looks like this:</p>
-<div class="language-yaml highlighter-rouge">
-<pre class="highlight"><code><span class="pi">-</span> <span class="s">name</span><span class="pi">:</span> <span class="s">John Doe</span>
- <span class="s">login_age</span><span class="pi">:</span> <span class="s">old</span>
- <span class="s">image</span><span class="pi">:</span> <span class="s">johndoe.jpg</span>
+<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">John Doe</span>
+ <span class="na">login_age</span><span class="pi">:</span> <span class="s">old</span>
+ <span class="na">image</span><span class="pi">:</span> <span class="s">johndoe.jpg</span>
-<span class="pi">-</span> <span class="s">name</span><span class="pi">:</span> <span class="s">Jane Doe</span>
- <span class="s">login_age</span><span class="pi">:</span> <span class="s">new</span>
- <span class="s">image</span><span class="pi">:</span> <span class="s">janedoe.jpg</span>
-</code></pre>
-</div>
+<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Jane Doe</span>
+ <span class="na">login_age</span><span class="pi">:</span> <span class="s">new</span>
+ <span class="na">image</span><span class="pi">:</span> <span class="s">janedoe.jpg</span>
+</code></pre></div></div>
<p>In the <code class="highlighter-rouge">_includes</code> folder, assume you have a file called <code class="highlighter-rouge">spotlight.html</code> with this code:</p>
-<div class="language-liquid highlighter-rouge">
-<pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">for</span><span class="w"> </span>person<span class="w"> </span>in<span class="w"> </span>include.participants<span class="w"> </span><span class="p">%}</span>
+<div class="language-liquid highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{%</span><span class="w"> </span><span class="nt">for</span><span class="w"> </span>person<span class="w"> </span>in<span class="w"> </span>include.participants<span class="w"> </span><span class="p">%}</span>
<span class="p">{%</span><span class="w"> </span><span class="kr">if</span><span class="w"> </span><span class="nv">person</span><span class="p">.</span><span class="nv">login_age</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"new"</span><span class="w"> </span><span class="p">%}</span>
<span class="p">{{</span><span class="w"> </span><span class="nv">person</span><span class="p">.</span><span class="nv">name</span><span class="w"> </span><span class="p">}}</span>
<span class="p">{%</span><span class="w"> </span><span class="kr">endif</span><span class="w"> </span><span class="p">%}</span>
<span class="p">{%</span><span class="w"> </span><span class="nt">endfor</span><span class="w"> </span><span class="p">%}</span>
-</code></pre>
-</div>
+</code></pre></div></div>
<p>Now when you insert the <code class="highlighter-rouge">spotlight.html</code> include file, you can submit the YAML file as a parameter:</p>
-<div class="highlighter-rouge">
-<pre class="highlight"><code><span class="p">{</span><span class="err">%</span><span class="w"> </span><span class="err">include</span><span class="w"> </span><span class="err">spotlight.html</span><span class="w"> </span><span class="err">participants=site.data.profiles</span><span class="w"> </span><span class="err">%</span><span class="p">}</span><span class="w">
-</span></code></pre>
-</div>
+<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>{% include spotlight.html participants=site.data.profiles %}
+</code></pre></div></div>
<p>In this instance, <code class="highlighter-rouge">site.data.profiles</code> gets inserted in place of <code class="highlighter-rouge">include.participants</code> in the include file, and the Liquid logic processes. The result will be <code class="highlighter-rouge">Jane Doe</code>.</p>