Skip to content

Instantly share code, notes, and snippets.

@jarednova
Created July 20, 2017 04:48
Show Gist options
  • Save jarednova/ccc94e3ba7679450ca83b0835ef6b59f to your computer and use it in GitHub Desktop.
Save jarednova/ccc94e3ba7679450ca83b0835ef6b59f to your computer and use it in GitHub Desktop.

Notice: Undefined offset: 0 in /Users/jared/Sites/timber-docs/generator/PHPDocsMD/Reflector.php on line 407

Notice: Undefined offset: 0 in /Users/jared/Sites/timber-docs/generator/PHPDocsMD/Reflector.php on line 407

Notice: Undefined offset: 0 in /Users/jared/Sites/timber-docs/generator/PHPDocsMD/Reflector.php on line 407

Notice: Undefined offset: 0 in /Users/jared/Sites/timber-docs/generator/PHPDocsMD/Reflector.php on line 407

Notice: Undefined offset: 0 in /Users/jared/Sites/timber-docs/generator/PHPDocsMD/Reflector.php on line 407

Notice: Undefined offset: 0 in /Users/jared/Sites/timber-docs/generator/PHPDocsMD/Reflector.php on line 407


title: "Timber\Archives" menu: main: parent: "reference"

The TimberArchives class is used to generate a menu based on the date archives of your posts. The Nieman Foundation News site has an example of how the output can be used in a real site (screenshot).

PHP

<?php
$context['archives'] = new TimberArchives( $args );

Twig

<ul>
{% for item in archives.items %}
    <li><a href="{{item.link}}">{{item.name}}</a></li>
    {% for child in item.children %}
        <li class="child"><a href="{{child.link}}">{{child.name}}</a></li>
    {% endfor %}
{% endfor %}
</ul>

HTML

<ul>
    <li>2015</li>
    <li class="child">May</li>
    <li class="child">April</li>
    <li class="child">March</li>
    <li class="child">February</li>
    <li class="child">January</li>
    <li>2014</li>
    <li class="child">December</li>
    <li class="child">November</li>
    <li class="child">October</li>
</ul>

Methods Overview

Name Type Returns/Description
__construct void
get_items array/string
items array the items of the archives to iterate through and markup for your page

__construct

__construct( mixed $args=null, string $base="" )

returns: void

Name Type Description
$args mixed array of arguments {
$base string any additional paths that need to be prepended to the URLs that are generated, for example: "tags"

get_items

get_items( mixed/array/string $args=null )

returns: array/string

Name Type Description
$args mixed/array/string

This class extends \Timber\Core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment