Created
April 24, 2014 05:03
-
-
Save zakhardage/11242120 to your computer and use it in GitHub Desktop.
Using article and comment variables to display product reviews
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% for article in blogs.reviews.articles %} | |
| {% assign article-handle = article.title | handle %} | |
| {% if article-handle == product.handle %} | |
| {% assign review-count = article.comments_count %} | |
| {% paginate article.comments by 50 %} | |
| {% for comment in article.comments %} | |
| {% assign star-count = star-count | plus:comment.name %} | |
| {% endfor %} | |
| {% endpaginate %} | |
| {% endif %} | |
| {% endfor %} | |
| {% assign review-avg = star-count | divided_by:review-count %} | |
| REVIEWS | |
| <span itemprop="rating">{{ review-avg }}/5 Stars</span> (based on {{ review-count }}) reviews) | |
| {% for article in blogs.reviews.articles %} | |
| {% assign article-handle = article.title | handle %} | |
| {% if article-handle == product.handle %} | |
| {% paginate article.comments by 50 %} | |
| {% for comment in article.comments %} | |
| {{ comment.name }} — {{ comment.content }} | |
| {% endfor %} | |
| {% endpaginate %} | |
| {% endif %} | |
| {% endfor %} | |
| {% form article %} | |
| <span class="star" onclick="rating('1')"></span> | |
| <span class="star" onclick="rating('2')"></span> | |
| <span class="star" onclick="rating('3')"></span> | |
| <span class="star" onclick="rating('4')"></span> | |
| <span class="star" onclick="rating('5')"></span> | |
| <input type="hidden" id="stars" name="comment[author]" value="" /> | |
| <input type="hidden" name="comment[email]" value="{{ shop.email }}" /> | |
| <textarea id="body" name="comment[body]" cols="40" rows="5"></textarea> | |
| <button type="submit">submit review</button> | |
| {% endform %} | |
| <script> | |
| function rating(value) { | |
| document.getElementById('stars').value = value; | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment