What is the most efficient way to code matrix blocks by type in a template? Is this the most efficient way to use matrix in a template where different block types need outputting in various area of the HTML markup? I have 9 block types that need to be placed in various areas of the HTML markup.

{# Create a variable with the matrix fields in #}
{% set var = entry.sofa %}

{# Is the block in the variable #}
{% if var.block.type('twoSeaterSofa') %}

    {# block is in variable #}
    {% for block in var.block.type('twoSeaterSofa') %}      
        {# output block #}
        {{ block.price }}
    {% endfor %}

{% endif %}


Grateful for any advice or code.
The right syntax to filter matrix blocks by block type is this (see Craft docs here):

{% for block in entry.myMatrixField.type('text') %}{% endfor %}


So you only have to remove the extra .block you have in your example code. I'd save the returned array of MatrixBlockModels to a variable and use the length filter to see if there are any blocks of this type.

{% set twoSeaterSofas = entry.sofa.type('twoSeaterSofa') %}
{% set threeSeaterSofas = entry.sofa.type('threeSeaterSofas') %}

&lt;!-- some HTML --&gt;

{% if twoSeaterSofas|length %}
    {% for block in twoSeaterSofas %}    
    {% endfor %}
{% endif %}

&lt;!-- more HTML --&gt;

{% if threeSeaterSofas|length %}
    {% for block in threeSeaterSofas %}    
    {% endfor %}
{% endif %}