OK folks, I'm stuck. Here's the scenario:

  • split blog posts into years by folder (blog/2014, blog/2013, etc) to maintain performance.
  • I use a "router" template to pass in the required variables so that site.com, site.com/blog and site.com/blog/2014 are all equivalent

I'd like my navigation to work properly. I've got it working so when I'm on the last page of a year, the "Older" link goes to the earlier year.

However, if I'm on the FIRST page of a non-current year (say, 2012) I simply cannot get it to go to the LAST page of the previous year (site.com/blog/2013&page=6, for example).

Logically I've solved it but because of this problem, it doesn't work.

I'm open for ideas. Code below.

                {{ var:passed_year is={year} }}
                {{ var:current_year is={current_date format='Y'} }}
                {{ var:next_year is="{{year|+:1}}" }}
                {{ var:last_year is="{{year|-:1}}" }}
                {{ var:first_in_year is="false" }}

                <ul class="pager">
                {{ if !year }}
                    {{ entries:pagination folder="{folder}" limit="4" taxonomy="{taxonomy}" since=since until=until}}
                            <li class="previous {{ if !previous_page }} disabled{{endif}}"><a href="{{ previous_page }}">Newer</a></li>
                            <li class="next {{ if !next_page }} disabled{{endif}}"><a href="{{ next_page }}">Older</a></li>
                    {{ /entries:pagination }}
                {{ else }}
                    {{# if not in current year #}}
                    {{ if "{var:passed_year}" != "{var:current_year}" }}
                        {{# figure out if we are at the beginning #}}
                        {{ entries:pagination folder="{folder}" limit="4" taxonomy="{taxonomy}" since=since until=until}}
                            {{ if !previous_page }}{{var:first_in_year is="true"}}{{ /if }}
                        {{ /entries:pagination }}

                        {{# if at the beginning, grab the last page from the NEWER year #}}
                        {{ if "{var:first_in_year}"=="true" }}
                            {{ entries:pagination folder="blog/{var:next_year}" limit="4" }}
                                <li class="previous"><a href="/blog/{{var:next_year}}{{last_page}}">Newer</a>
                            {{ /entries:pagination }}
                        {{ else }}
                            <li class="previous"><a href="{{ previous_page }}">Newer</a></li>
                        {{ /if }}
                    {{# I'm in the current year #}}    
                    {{ else }}
                        {{ entries:pagination folder="{folder}" limit="4" taxonomy="{taxonomy}" since=since until=until}}
                                <li class="previous {{ if !previous_page }} disabled{{endif}}"><a href="{{ previous_page }}">Newer</a></li>
                        {{ /entries:pagination }}
                    {{ /if }}

                    {{# now put the Older link in #}}
                    {{ entries:pagination folder="{folder}" limit="4" taxonomy="{taxonomy}" since=since until=until}}
                        {{ if next_page }}
                            <li class="next"><a href="{{ next_page }}">Older</a></li>
                        {{ else }}
                            <li class="next"><a href="/blog/{{var:last_year}}">Older</a></li>
                        {{ /if }}
                    {{ /entries:pagination }}
                {{ /if }}
                </ul>

Specifically, this:

{{ if "{var:passed_year}" != "{var:current_year}" }}

Doesn't work, no matter how I try it with quotes/braces, etc

Answered by Jack McDade! Go to answer.