New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create object on the templating side? #387

Closed
graygilmore opened this Issue Jul 21, 2014 · 7 comments

Comments

Projects
None yet
3 participants
@graygilmore

graygilmore commented Jul 21, 2014

I've been creating arrays rather crudely like this:

{% assign array_name = 'value-1|value-2|value-3' | split: '|' %}

But now I'm in a situation where I'd like to create an object and have proper key and value. Is this possible to accomplish on the templating side?

@graygilmore

This comment has been minimized.

graygilmore commented Jul 21, 2014

I found a small work-around where I create two arrays:

{% assign sortHandles = "manual|price-ascending|price-descending|title-ascending|title-descending|created-ascending|created-descending|best-selling" | split: "|" %}
{% assign sortTitles = "Featured|$ Low to High|$ High to Low|A-Z|Z-A|Oldest to Newest|Newest to Oldest|Best Selling" | split: "|" %}

{% for handle in sortHandles %}
  {% if collection.sort_by == blank and collection.default_sort_by == handle %}
    <option value="{{handle}}" selected>{{ sortTitles[forloop.index0] }}</option>
  {% elsif collection.sort_by == handle %}
    <option value="{{handle}}" selected>{{ sortTitles[forloop.index0] }}</option>
  {% else %}
    <option value="{{handle}}">{{ sortTitles[forloop.index0] }}</option>
  {% endif %}
{% endfor %}
@fw42

This comment has been minimized.

Member

fw42 commented Jul 21, 2014

Hm no I don't think this is possible (or supposed to be possible, really) in Liquid :-(

@graygilmore

This comment has been minimized.

graygilmore commented Jul 21, 2014

Yea, ideally all of that information would have been presented to me in the collection object but I think the sorting feature is still pretty fresh and documentation hasn't been completed yet.

@fw42 fw42 closed this Jul 23, 2014

@fw42 fw42 added the Question label Jul 23, 2014

@fw42

This comment has been minimized.

Member

fw42 commented Jul 23, 2014

This GitHub repo isn't really the right place to ask questions about how to do certain things in the templates. If you are using this for Shopify, feel free to ask questions like this in the Shopify forums.

@graygilmore

This comment has been minimized.

graygilmore commented Jul 23, 2014

Unfortunately, this was the fastest reply I've ever received. Most technical questions are left unanswered in the forums. I'll try there next time.

@fw42

This comment has been minimized.

Member

fw42 commented Jul 23, 2014

Sorry to hear that :-( For this particular question, I know it was asked before several times, so maybe try searching the forums if you don't get a fast reply.

@eddyparkinson

This comment has been minimized.

eddyparkinson commented Feb 6, 2018

@fw42 "Shopify forums" - please allow posts to threads marked "This post is outdated".

Please do us small a favour. Please allow posts to threads marked "This post is outdated". "Shopify forums" has many valuable threads. Many are marked "This post is outdated", this is fine. It would be great if we could still post to such threads. So that useful info can be added to good threads.

I am guessing there is no way to port the "Shopify forums" to stackoverflow, stackoverflow has great features.

e.g I wanted to add the above liquid example to:
https://ecommerce.shopify.com/c/ecommerce-design/t/how-to-assign-an-object-in-liquid-112278#write-comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment