Error when using if statement in template
It is expecting an {% endpaginate %}.


{% set categoryName = craft.request.lastSegment %}
{% if categoryName == 'all' %}
    {% paginate craft.entries.section('photo').limit(6) as entries %}
    ...
    {% endpaginate %}
{% else %}
    {% set category = craft.categories.slug(categoryName) %}
    {% paginate craft.entries.section('photo').relatedTo(category).limit(6) as entries %}
    ...
    {% endpaginate %}
{% endif %}


Update: if you want to define the paginate block separately to keep your code dry you can assign the element criteria model to a variable first. See carlcs' answer above/below for another way to do the same.


{% set categoryName = craft.request.lastSegment %}
{% if categoryName == 'all' %}
    {% set ecm = craft.entries.section('photo').limit(6) %}
{% else %}
    {% set category = craft.categories.slug(categoryName) %}
    {% set ecm = craft.entries.section('photo').relatedTo(category).limit(6) %}
{% endif %}

{% paginate ecm as entries %}
    ...
{% endpaginate %}