Recipe info (ratings, prep time, etc.) on the blog index page

Recipe info (ratings, prep time, etc.) on the blog index page

If you are looking to put some extra information (for example: recipe ratings, calories, prep time, etc.) on your blog index page (or anywhere else on your site where you have access to the {{ article }} object, follow this guide.

We will be taking a bit of code from the main recipekit.liquid file (which you should reference for all other information / data if you need it).

{%- assign rk_resource_id = article.id | downcase -%} {%- assign rk_mf = article.metafields.recipekit[rk_resource_id] -%} {%- if rk_mf != blank -%}

{% comment %} Grab recipe rating, use with {{ rating_count }} and {{ current_rating }} in your HTML {% endcomment %} {%- assign current_rating = rk_mf.recipe_rating | ceil | default: 5 | at_most: 5 -%} {%- assign current_decimal_rating = rk_mf.recipe_rating | round: 1 | default: 5 | at_most: 5 -%} {%- assign rating_count = rk_mf.rating_count | default: '1' | at_least: '1' -%}

{%- comment -%} Prep & Cook Time Formatting. Use with {{ rk_prep_time }} and {{ rk_cook_time }} in your HTML {%- endcomment -%} {% assign rk_prep_time_split = rk_mf.prep_time | split: ' ' %} {% assign rk_prep_time = rk_prep_time_split | first %} {% assign rk_prep_duration = rk_prep_time_split | last %} {% if rk_prep_time contains '.' and rk_prep_duration == 'hours' %} {% assign rk_prep_hour_time = rk_prep_time | split: '.' | first %} {% assign rk_prep_lang_hours = rk_prep_hour_time | plus: 0 | pluralize: rk_lang_hour, rk_lang_hours %} {% assign rk_prep_minute_time = rk_prep_time | split: '.' | last %} {% assign rk_prep_lang_minutes = rk_prep_minute_time | plus: 0 | pluralize: rk_lang_minute, rk_lang_minutes %} {% assign rk_prep_time = rk_prep_hour_time | append: ' ' | append: rk_prep_lang_hours | append: ' ' | append: rk_prep_minute_time | append: ' ' | append: rk_prep_lang_minutes %} {% elsif rk_prep_duration == 'hours' %} {% assign rk_prep_duration = rk_prep_time | plus: 0 | pluralize: rk_lang_hour, rk_lang_hours %} {% assign rk_prep_time = rk_prep_time | append: ' ' | append: rk_prep_duration %} {% elsif rk_prep_duration == 'minutes' %} {% assign rk_prep_duration = rk_prep_time | plus: 0 | pluralize: rk_lang_minute, rk_lang_minutes %} {% assign rk_prep_time = rk_prep_time | append: ' ' | append: rk_prep_duration %} {% endif %}

{% assign rk_cook_time_split = rk_mf.cook_time | split: ' ' %} {% assign rk_cook_time = rk_cook_time_split | first %} {% assign rk_cook_duration = rk_cook_time_split | last %} {% if rk_cook_time contains '.' and rk_cook_duration == 'hours' %} {% assign rk_cook_hour_time = rk_cook_time | split: '.' | first %} {% assign rk_cook_lang_hours = rk_cook_hour_time | plus: 0 | pluralize: rk_lang_hour, rk_lang_hours %} {% assign rk_cook_minute_time = rk_cook_time | split: '.' | last %} {% assign rk_cook_lang_minutes = rk_cook_minute_time | plus: 0 | pluralize: rk_lang_minute, rk_lang_minutes %} {% assign rk_cook_time = rk_cook_hour_time | append: ' ' | append: rk_cook_lang_hours | append: ' ' | append: rk_cook_minute_time | append: ' ' | append: rk_cook_lang_minutes %} {% elsif rk_cook_duration == 'hours' %} {% assign rk_cook_duration = rk_cook_time | plus: 0 | pluralize: rk_lang_hour, rk_lang_hours %} {% assign rk_cook_time = rk_cook_time | append: ' ' | append: rk_cook_duration %} {% elsif rk_cook_duration == 'minutes' %} {% assign rk_cook_duration = rk_cook_time | plus: 0 | pluralize: rk_lang_minute, rk_lang_minutes %} {% assign rk_cook_time = rk_cook_time | append: ' ' | append: rk_cook_duration %} {% endif %} {%- comment -%} End Time Formatting {%- endcomment -%}

{% comment %} Example usage HTML that probably exists in your blog.liquid file {% endcomment %}


{{ article.title }}


Recipe rated {{ current_rating }} stars by {{ rating_count }} users


Prep: {{ rk_prep_time }}


Cook: {{ rk_cook_time }}


{% endif %}

To add the recipe stars rating to your article card, use this code:

{%- assign rk_resource_id = article.id | downcase -%} {%- assign rk_mf = article.metafields.recipekit[rk_resource_id] -%} {%- if rk_mf != blank -%}

{% comment %} Grab recipe rating {% endcomment %} {%- assign current_rating = rk_mf.recipe_rating | ceil | default: 5 | at_most: 5 -%} {%- assign current_decimal_rating = rk_mf.recipe_rating | round: 1 | default: 5 | at_most: 5 -%} {%- assign rating_count = rk_mf.rating_count | default: '1' | at_least: '1' -%}

{{ article.title }}

{% for i in (1..5) %} {% if i <= current_rating %} {% else %} {% endif %} {% endfor %}
({{ rating_count }} {{ rating_count | pluralize: 'review', 'reviews' }})
{% endif %}
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us