9

I'd like to output the Names of Matrix Blocks. I know you can filter by block types e.g.

{% for block in entry.myMatrixField.type('text, heading') %}
{% if block.type == "heading" %}
    <h3>{{ block.heading }}</h3>
{% else %}
    {{ block.text | markdown }}
{% endif %}
{% endfor %}

I know I could use {{ block.type }} and get the block type's handle but, I want to included the actual Name of the block type itself too.

For example, something like this:

{{ block.type.name }}

Is this currently possible?

Natetronn
  • 1,375
  • 2
  • 12
  • 20

2 Answers2

13

block.type is actually an alias for a getType() function, which returns a new MatrixBlockTypeModel object. Those will output their handle by default, which is why it's possible to compare block.type against block type handles. But MatrixBlockTypeModel also has a handle property, so this is totally possible:

{{ block.type.handle }}
ianp
  • 163
  • 12
Brandon Kelly
  • 34,307
  • 2
  • 71
  • 137
2

It does not appear to be in the matrix block model. http://buildwithcraft.com/docs/templating/matrixblockmodel

Steve Adams
  • 1,671
  • 2
  • 15
  • 27