1

While trying to assign a global CSS class based on the order of the categories based on the drag and drop in the admin editor.

The categories I'm using is a single 1 level deep category.

It seems like the lft and rgt values are the only one that changes when they are moved.

It appears I can just divide the lft number by 2 and I get a sequence of the order (1,2,3,4,5,6).

{%- for category in relatedCategories -%}
  <a href="{{ category.url | default }}"
    class="ArticleCard-meta-link ArticleCard-meta-link--{{ category.lft /2 }}"
  >{{ category.title }}</a>
{%- endfor -%}

How do the values lft and rgt get assigned and is this a correct assumption that dividing it will always get an incremental pattern?

  • I don't have an answer for you, but the pattern that Craft uses for structures and categories (things that have depth, hierarchy and order) is the Nested Set model. You can read about it and the math involved here: en.wikipedia.org/wiki/Nested_set_model – Brad Bell Sep 6 '18 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.