Tweak Library

Colour Filter Swatch

A "brands" menu, which shows all of your brands, as a text list.

Industries

  • Fashion
  • Furniture & Homewares
  • Health & Beauty
  • Sports & Recreation
  • Jewellery & Accessories
  • Arts & Crafts

Wireframe

Review Stars

Coding Instructions

Step 1. Add the code to the sidebar

Open cms/includes/sidebar.template.html and replace the code within the [%param *body%] for [%PRODUCT_FILTER%] with the below:

[%if [@filter_name@] eq 'Colour' %]
    [%data id:'selected' if:'==' value:'1'%]
    [%param *if_true%]##-->
        <li class="filter-remove filter filter-colour">
            <a href="[@remove_single_url@]" rel="nofollow" data-toggle="tooltip" title="[@name@]"
                style="
                [%if [@variation_swatch@] ne ''%]
                background-color:[@variation_swatch@]
                [%else%]
                background-image:url('[@config:homeurl@]/assets/itmspecific/[@id@].png')
                [%/if%]">
            </a>
        </li>
    [%/param%]
    [%param *if_false%]##-->
        <li class="filter filter-colour">
            <a href="[@url@]" rel="nofollow" data-toggle="tooltip" title="[@name@]"
                style="
                [%if [@variation_swatch@] ne ''%]
                background-color:[@variation_swatch@]
                [%else%]
                background-image:url('[@config:homeurl@]/assets/itmspecific/[@id@].png')
                [%/if%]">
            </a>
        </li>
    [%/param%]
[%/data%]
[%else%]
    [%data id:'selected' if:'==' value:'1'%]
        [%param *if_true%]
            <li class="filter-remove filter"><a href="[@remove_single_url@]" class="list-group-item" rel="nofollow">
                [@name@] <span class="text-muted"></span></a>
            </li>
        [%/param%]
        [%param *if_false%]
            <li class="filter">
                <a class="list-group-item" href="[@url@]"> [@name@] <span class="text-muted"></span></a>
            </li>
        [%/param%]
    [%/data%]
[%/if%]

Notes On The Above Code

This code updates the filter for the "Colour" specific. In order for the above to work, the specific name itself must be set to "Colour".

Firstly, the code tests to see whether an image exists for that particular specific value, and displays it if so. In the absence of an image, it displays the "swatch" value for the specific instead.

An important point is that the images that are displayed for each specific value must be PNG files, otherwise they won't show.

Step 2. Add the CSS

Add the following CSS to the appropriate stylesheet:

.filter-colour {
    display: inline-block;
    padding: 10px 1px 0 8px;
}
.list-group > li + .filter.filter-colour > a:before {
    content: '';
}
.list-group > li + .filter.filter-colour > a {
    display: block;
    width: 30px;
    height: 30px;
    border-radius: 15px;
    box-shadow: 1px 1px 2px #D6D6D6;
}
.filter-remove > a {
    border: 2px solid #AFAFAF;
}

Step 3. Shuffle elements or update styles to suit

Update the CSS to suit, if necessary - for example, the padding between each swatch may need to be adjusted.

Final Result

Download Files

Download Files