Need help resolving liquid syntax error in shipping confirmation code?

Hi!

I added some code to the shipping confirmation email, but I get the error “Body html Liquid syntax error: Unexpected outer ‘else’ tag”

I checked my work many times and can’t figure it out. Any ideas?

{% if fulfillment.item_count == item_count %}
{% capture shipment_name %}Your order is{% endcapture %}
{% elsif fulfillment.item_count > 1 %}
{% if fulfillment_status == 'fulfilled' %}
{% capture shipment_name %}The last items in your order are{% endcapture %}
{% else %}
{% capture shipment_name %}Some items in your order are{% endcapture %}
{% endif %}
{% else %}
{% if fulfillment_status == 'fulfilled' %}
{% capture shipment_name %}The last item in your order is{% endcapture %}
{% else %}
{% capture shipment_name %}One item in your order is{% endcapture %}
{% endif %}
{% endif %}

{% capture email_title %}{{ shipment_name }} on the way! {% endcapture %}
{% capture email_body %}
{% if shipping_method.title contains "First" %}
Your order is shipping via USPS First Class. You can expect to receive it within 10 - 14 business days.
{% else %}
{{ shipment_name }} on the way to you. It is coming via **{{ fulfillment.tracking_company }}**  and has the tracking
number **{{ fulfillment.tracking_numbers }}** Please note: It could take up to 48 hours for your tracking link to
activate.
{% endif %}

{% if shipping_method.title contains "Media" %}
Please note: The tracking may indicate "pre-shipment" status for a period of time, but the shipment is indeed in
transit. USPS does not provide updates until closer to delivery with this ship method.
{% else %}

{% endif %}{% endcapture %}

{% capture email_emphasis %}Estimated delivery date: **{{fulfillment.estimated_delivery_at | date: format: 'date'}}**{% endcapture %}

  
  
  
  
  
  

  

    <table>

      
        
          <table>

  
    
      

        <table>

          
            

              <table>

                <tr>

                  <td>

                    {%- if shop.email_logo_url %}
                      
                    {%- else %}
                      # 
                        {{ shop.name }}
                      
                    {%- endif %}
                  

</td>

                    <td>

                      
                        Order {{ order_name }}
                      
                    

</td>

                </tr>

              </table>

            
          
        </table>

      
    
  
</table>

          <table>

  
    
      
        <table>

          
            
              
            ## {{ email_title }}
                      

{{ email_body }}

                      {% if fulfillment.estimated_delivery_at %}
                      

{{ email_emphasis }}

                      {% endif %}
                      {% unless shipping_method.title contains "First" %}
                      {% if order_status_url %}
                      <table>

                        
                          
                            
                                {% if shipping_method.title contains "Media" %}
                                
                                {% else %}
                                
                                {% endif %}
                              <table>

                              <tr>
<td>

[Track your order!](https://store.wordonfire.org/apps/trackingmore?order={{ order.name }}&email={{ order.email }})
                                

</td>
<td>

Track your order!
                                

</td>
</tr>

                            </table>
                            {% if shop.url %}
                            <table>

                              <tr>

                                <td>

or view
                                    your receipt

</td>

                              </tr>

                            </table>
                            {% endif %}

                          
                        
                      </table>

                      {% else %}
                      {% if shop.url %}
                      <table>

                        
                          
                            <table>

                              <tr>

                                <td>

Visit our
                                    store

</td>

                              </tr>

                            </table>
                          
                        
                      </table>
                      {% endif %}
                      {% endif %}
                      {% endunless %}

                    
                  
                </table>
              
            
          
        </table>

            {% else %}
              {% if shop.url %}
    <table>

      
        
          <table>

            <tr>

              <td>

Visit our store

</td>

            </tr>

          </table>
        
      
    </table>
{% endif %}

            {% endif %}
            {% if fulfillment.tracking_numbers.size > 0 %}
  

    

    {% if fulfillment.tracking_numbers.size == 1 and fulfillment.tracking_company and fulfillment.tracking_url %}
      {{ fulfillment.tracking_company }} tracking number: {{ fulfillment.tracking_numbers.first }}
    {% elsif fulfillment.tracking_numbers.size == 1 %}
      Tracking number: {{ fulfillment.tracking_numbers.first }}
    {% else %}
      Tracking numbers:

      {% for tracking_number in fulfillment.tracking_numbers %}
        {{ tracking_number }}

      {% endfor %}
    {% endif %}
  

{% endif %}

            
          
        </table>
      
    
  

{% endunless %}

          <table>

  
    
      
        <table>

          <tr>

            <td>

              ### Items in this shipment
            

</td>

          </tr>

        </table>
        <table>

          
            
              
            

  {% for line in fulfillment.fulfillment_line_items %}
  {% endfor %}
<table>

    
      <table>

        <tr>
<td>

          {% if line.line_item.image %}
            
          {% endif %}
        

</td>

        <td>

          {% if line.line_item.product.title %}	
            {% assign line_title = line.line_item.product.title %}	
          {% else %}	
            {% assign line_title = line.line_item.title %}	
          {% endif %}

          {% if line.quantity < line.line_item.quantity %}
            {% capture line_display %} {{ line.quantity }} of {{ line.line_item.quantity }} {% endcapture %}
          {% else %}
            {% assign line_display = line.line_item.quantity  %}
          {% endif %}

          {{ line_title }} × {{ line_display }}

          {% if line.line_item.selling_plan_allocation %}
            {{ line.line_item.selling_plan_allocation.selling_plan.name }}

          {% endif %}

          {% if line.line_item.refunded_quantity > 0 %}
            Refunded
          {% endif %}

          {% if line.line_item.discount_allocations %}
            {% for discount_allocation in line.line_item.discount_allocations %}
              {% if discount_allocation.discount_application.target_selection != 'all' %}
                
                  
                  
                    {{ discount_allocation.discount_application.title | upcase }}
                    (-{{ discount_allocation.amount | money }})
                  
                
              {% endif %}
            {% endfor %}
          {% endif %}
        

</td>

      </tr>
</table>
    
  </table>

            
          
        </table>
      
    
  
</table>

          <table>

  
    
      
        <table>

          <tr>

            <td>

              
              

If you have any questions, reply to this email or contact us at [{{ shop.email }}](mailto:{{ shop.email }})
Would you like to return this order? [Click Here.](https://word-on-fire.returnly.com)

            

</td>

          </tr>

        </table>
      
    
  
</table>

        
      
    
  

It looks like this {% else %} doesn’t have an associated {% if %} before it:

I think the best way to debug this would be:

  1. Copy all that code and put in a text editor, so you can see more of it and edit better than inside Shopify

  2. Indent your code properly, for example:

{% if 1 == 1 %}
  {% if a == a %}
    this is properly indented
  {% endif %}
{% endif %}

{% if 1 == 1 %}
{% if a == a %}
this block is not indented, making it harder to track blocks when your code gets long
{% endif %}
{% endif %}

Once you have your code indented, it will be easy to track down the misaligned if / else blocks.

You could also copy all your current code to a text editor and save that, then in Shopify revert to the default template, and re-add in your customizations, being careful to make sure any mods you make don’t disrupt the condition if / else logic.