52260

How to capture if current vendor is selected

Question:

In my sidebar on the collection pages and index, I have listed all vendors with the code below. Now I want to add an .active class to the <li> when that particular vendor is selected. I want to do the same thing with a list of product types. How do I check which vendor is selected?

I tried {% if collection.handle == vendor %}. But it returns null as it can only capture collections names.

<ul class="nav"> {% for vendor in shop.vendors %} <li class="collection-container {% if collection.handle == vendor %}active {% endif %}">{{ vendor | link_to_vendor }}</li> {% endfor %} </ul>

Please note that the url is constructed as /collections/types?q=Nike and that after the = comes the vendor. I want to try to somehow capture on which current collection the user is navigating and add an active tag throughout the foreach loop.

I realise it can be done by creating collections for each vendor and product type and using collection.handel, but I am interested in trying to solve it by capturing the last bit of the URL.

Answer1:

**show vendor filter use these code **<br /><ul class="filter"><br />{% for Vendor in shop.vendors %}<br />{% if shop.vendors contains Vendor %}<br />{% if collection.current_vendor == Vendor %} <li class="active"> {{ Vendor | link_to_vendor }}</li><br />{% else %}<br /><li>{{ Vendor | link_to_vendor }}</li>{% endif %}<br />{% endif %}<br />{% endfor %}<br /></ul>

<strong>if you want to short vendor try these code</strong><br /><ul class="filter"><br />{% assign myvendor = 'samsung,xaomi,Nokia' | split:"," %}<br />{% for Vendor in myvendor %}<br />{% if shop.vendors contains Vendor %}<br />{% if collection.current_vendor == Vendor %} <li class="active"> {{ Vendor | link_to_vendor }}</li><br />{% else %}<br /><li>{{ Vendor | link_to_vendor }}</li>{% endif %}<br />{% endif %}<br />{% endfor %}<br /></ul>

Recommend

  • Undefined reference to `SHA1'
  • Can undefined behaviour cause an exception in a function defined as never throwing an exception?
  • cheap stereo vision camera + opencv [closed]
  • Three.js picking is not working correctly with custom geometry
  • implementing euclidean distance based formula using numpy
  • isotope shakes after the transition
  • Angular Library Modules export components, services and others from module
  • maximizing profit for given stock data via DP
  • Failure to Read Updated AnyLogic DB Values
  • Putting multiple films in a circle in Raphael/Joint.js
  • get value using jquery
  • AJAX calls - where does logic go?
  • Reveal Icon Button - Bootstrap 3
  • Unknown type name with typedef struct in C
  • QueryOver - add restriction on primitive collection
  • Installing Kohana on OpenShift?
  • Getting specific color for specific value using JSON data
  • Visual Studio MSB3721 error when compiling a __device__ function call from another file
  • How to sort by Lucene.Net field and ignore common stop words such as 'a' and 'the
  • Unable to connect to Azure MySQL Database through Azure Function - C#
  • Slick: How can I combine a SQL LIKE statement with a SQL IN statement
  • How can i use JQuery fadeTo() in IE 7?
  • Why am I getting an Argument exception when creating event handler dynamically?
  • ASP.NET GridView throws: The version of SQL Server in use does not support datatype 'date'
  • How to get the Owner of the ContextMenu (from Silverlight 4 toolkit)?
  • Scripting Support For Image Filtering in DigitalMicrograph
  • Delete a ListItem by clicking the ImageView within the ListItem
  • Get name of days between two date in ios?
  • How to add html image in to velocity template file to send email?
  • Slice assignment to tensorflow variable
  • How to use Flask's render_template from an ajax POST form submit
  • Year over Year Stats from a Crossfilter Dataset
  • Can I read another applications memory?
  • Why is ordered choice in pyparsing failing for my use case?
  • Neo4j…how to get a visual representation of my data?
  • How to use Streams api peek() function and make it work?
  • read part of h5 dataset python
  • Background transfer download task failed when app was closed
  • Firebase: How to read from external DB?
  • Write to .csv file with PHP (Commas in Data Error)