liquid

Filter or group a collection in Liquid

爷,独闯天下 提交于 2019-12-10 21:31:29
问题 For a simple personal Jekyll blog, I want to group my site.posts by an attribute on post , lang (language). This is either "en", "nl" or nil. I then want to render two lists of posts. Currently I have: <section lang="nl"> <h2>Nederlandse Artikelen</h2> <ul class="posts"> {% for post in site.posts limit:50 %} {% if post.lang == "nl" %} {% include li_for_post_with_date.yml %} {% endif %} {% endfor %} </ul> <a href="archief.html">Archief »</a> </section> <section lang="en"> <h2>English Articles<

How to retrieve the current post index number in Jekyll?

点点圈 提交于 2019-12-10 20:51:41
问题 Is there a way to get the current post index number from site.posts ? {{ site.posts | size }} is the total number of posts. What I need is something like {{ site.posts.index }} or {{ page.index }} . I am trying to display a counter on each post page. Example: Post 43 of 2654 回答1: In a for loop you can get current item index in two ways : {% for post in site.posts %}{{ forloop.index }}{% endfor %} # will print 123... or {% for post in site.posts %}{{ forloop.index0 }}{% endfor %} # will print

Shopify: Why does Liquid sometimes use {%- instead of {%?

守給你的承諾、 提交于 2019-12-10 19:45:46
问题 I've been looking through the code of the default theme, and I've noticed that sometimes they use the {% tag to indicate Liquid code (as per the documentation), but other times they use {%- . For example: {% case section.settings.image_size %} {% when 'small' %} {%- assign product_image_width = 'medium-up--one-third' -%} {%- assign product_description_width = 'medium-up--two-thirds' -%} I cannot find a single example of {%- in the Liquid documentation, either on the Shopify site, or on GitHub

How to fix: Liquid Exception: Tag '{%' was not properly terminated with regexp: /\%\}/?

给你一囗甜甜゛ 提交于 2019-12-10 18:54:32
问题 I'm getting this output from my Jekyll website generator Liquid Exception: Tag '{%' was not properly terminated with regexp: /\%}/ What's going on? 回答1: It turns out that you've probably made a formatting error in your template. For example: {% if site.ALERT or site.ALERT_en %} will break but {% if site.ALERT or site.ALERT_en %} is fine. 回答2: I had the issue with Octopress and the solution was to follow the advice by prigazzi: The file that's causing this problem in octopress, is category

Is there a way to evaluate string with liquid tags

回眸只為那壹抹淺笑 提交于 2019-12-10 18:17:17
问题 I need to provide page content reference list (it should contain references on sections on page). The only way which I can see is to use page.content and parse it, but I stumbled on problem with data evaluation. For example I can pull out this string from page.content : {{site.data.sdk.language}} SDK but there is no way to make jekyll process it, it outputs as is. Also I want to make it possible to create cross-pages links (on specific section on page, but that link generated by another

jekyll: check if there are no posts

拥有回忆 提交于 2019-12-10 15:38:14
问题 How can I check if there are no posts in the _posts folder? So far, I've tried {% if site.posts == null %} <p>No posts...yet.</p> {% endif %} and {% if site.posts == nil %} <p>No posts...yet.</p> {% endif %} Is this possible in Liquid? 回答1: Grab the size of the posts array and then compare that to 0: {% assign psize = site.posts | size %} {% if psize == 0 %} <p>No posts...yet.</p> {% endif %} 来源: https://stackoverflow.com/questions/46208588/jekyll-check-if-there-are-no-posts

Two column Jekyll layout, separated by tags?

一笑奈何 提交于 2019-12-10 11:23:51
问题 I'm currently working on a Jekyll blog at the moment, and I'd like to put my markdown files in this format: <div class="row"> <div class="col-md-6"> </div> <div class="col-md-6"> </div> </div> I want my code blocks in one column and everything else (text, headers, etc.) in the other column so that I have side-by-side explanations of my code. Is there any way to do this? It seems Markdown and the Liquid templating engine is very restrictive in this regard. Thanks! 回答1: You can get desired

Shopify liquid get related blog posts

喜夏-厌秋 提交于 2019-12-10 10:48:23
问题 In shopify I am using liquid templating to get blog posts which are related to products by their tags, like so: <ul> {% for article in blogs.blog.articles %} {% if article.tags contains product.handle %} <li><a href="{{ article.url }}"><p>{{ article.title }}</p></a></li> {% endif %} {% endfor %} </ul> However, if there are no related posts, I would like to display a message such as "No related posts!" My question is how would I do that? I have contemplated trying to get the articles into an

How to override erb with liquid?

坚强是说给别人听的谎言 提交于 2019-12-10 10:34:26
问题 I've added a theming directory to my app as described here, using prepend_view_path . It works as expected. I can now add a view structure in my app under app/themes/my_theme/views Now, I want to be able to override erb templates by dropping in a .liquid file, which will render right off the controller action. For example, I want to override app/views/pages/home.html.erb : <h1><%= t 'it_works' %></h1> ...with app/themes/my_theme/views/pages/home.liquid <h1>It works with {{ "liquid" }}</h1> I

Can the Liquid Ruby template engine deal with Rails forms?

这一生的挚爱 提交于 2019-12-10 09:46:31
问题 I've been searching for a template engine to allow users to create lessons and exercises online easily. Seems like Liquid is the most popular for use in Rails. Can Liquid users easily create rails forms? Normally I create forms in ERB with: <%= form_for(@lesson) do |f| %> <% if @lesson.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@lesson.errors.count, "error") %> prohibited this lesson from being saved:</h2> <ul> <% @lesson.errors.full_messages.each do |msg| %> <li><%= msg %>