Perch Block nth of type

  • Is it possible to get the index number of the block type? For example, if I had 3 different blocks (a, b, and c), and the blocks were output on a page like this:


    - block a (1)

    - block b (1)

    - block a (2)

    - block c (1)

    - block b (2)

    - block b (3)

    - block a (3)


    ^ Where the number in the brackets represents the amount of times the block has been output on the page.


    The problem I'm trying to solve:

    I have a 'pull quote' block type. The second time it's used on the page I'd like to reverse it so that the text floats on the left instead of the right. I've thought about just adding this as a different block type but it would be cool to do this automatically.

  • I thought of that at first, but the whole nth-of-type is a bit of a misnomer; it would need to be more like an index of the block type.


    Nth of type would give me something like this:


    - block a (1) (nth-of-type: 1)

    - block b (1) (nth-of-type: 2)

    - block a (2) (nth-of-type: 3)

    - block c (1) (nth-of-type: 4)

    - block b (2) (nth-of-type: 5)

    - block b (3) (nth-of-type: 6)

    - block a (3) (nth-of-type: 7)

  • Hmmm I suppose it could just be a span instead of a div. No other elements on the page are spans at that particular level in the DOM.


    Feels a bit fragile, but good back up if nothing else materialises :)

    Thanks for the suggestion.


    I have a feeling it's not possible to do it how I want but I'll leave the thread open a little longer just in case I've overlooked something!