Code for page based customer feedback

by Chelsea - Member - 02:42AM, Jun 23, 2008

Props to Christina for creating the original Meta description code. This really was very easy; I was able to alter the code to suit my needs in about 2 minutes, once I read the liquid primer.

Basically, this allows you to display customer feedback on pages based on the page name, using a blog as the repository for the information.

        <!-- START: CUSTOMER FEEDBACK -->
<div>
{% assign maxwords = 20 %}
{% assign indexblog = 'frontpage' %}
{% assign feedback = 'feedback' %}
{% assign welcomereplacement = 'Welcome' %}
{% assign ourcollections = 'Our collections' %}

{% capture feedback_default %}
    {% case template %}
        {% when 'collection' %}
            {{page_title}}{% if collection.description.size > 0 %}: {{collection.description | strip_html | truncatewords:maxwords}}{% endif %}
        {% when 'product' %}
            {{page_title}}{% if product.description.size > 0 %}: {{product.description | strip_html | truncatewords:maxwords}}{% endif %}
        {% when 'blog' %}
            {% if blog.articles.size == 1 %}
                {% for article in blog.articles %}
                    {{ article.title }}: {{article.content | strip_html | truncatewords:maxwords}}
                {% endfor %}
            {% else %}
                {{page_title}}
            {% endif %}
        {% else %}
             {{shop.name}}: {% if blogs[indexblog].articles.size > 0 %}: {% for article in blogs[indexblog].articles limit:1 %}{{ article.title }}: {{article.content | strip_html | truncatewords:maxwords}}{% endfor %}{% endif %}
    {% endcase %} 
{% endcapture %}

{% if blogs[feedback].articles.size > 0 %}
    {% capture feedback_title_array %}
        {% for article in blogs[feedback].articles %}{{article.title}}{% endfor %}
    {% endcapture %}
    {% if feedback_title_array contains page_title %}
        {% for article in blogs[feedback].articles %}
            {% capture feedback_title %}{{article.title}}{% endcapture %}
            {% capture feedback_content %}{{article.content |strip_html}}{% endcapture %}
            {% case template %}
                {% when 'blog' %}
                    {% if blog.articles.size == 1 %}
                        {% for article in blog.articles %}
                            {% if feedback_title contains article.title %}
                                {{feedback_title}}: {{feedback_content}}
                            {% endif %}
                        {% endfor %}
                    {% else %}
                        {% if blog.title == feedback_title %}
                            {{feedback_title}}: {{feedback_content}}
                        {% endif %}
                    {% endif %}
                {% when 'index' %}
                    {% if feedback_title == 'Welcome' %}
                        {{welcomereplacement}}: {{feedback_content}}
                    {% endif %}
                {% when 'list-collections' %}
                    {% if feedback_title == 'Collections' %}
                        {{ourcollections}}: {{feedback_content}}
                    {% endif %}
                {% else %}
                    {% if page_title == feedback_title %}
                    {{feedback_title}}: {{feedback_content}}
                    {% endif %}
            {% endcase %}
        {% endfor %}
    {% else %}
        {{feedback_default}}
    {% endif %}
{% else %}
    {{feedback_default}}
{% endif %}

<br /><br />
<a href="http://YOURSHOP.COM/blogs/feedback/"> see customer feedback...</a>
</div>

1) Create a blog called ‘feedback’
2) Create blog entries with the same titles as your pages
3) Substitute your URL in the code above where is says YOURSHOP.COM
4) Drop this code into your theme.liquid template where you would like it to display.

Thanks again Christina!

You must login to post a comment!

Don't have an account yet? Sign up for one.