New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generators for creating new content #45

Closed
yosymfony opened this Issue Aug 4, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@yosymfony
Copy link
Member

yosymfony commented Aug 4, 2015

Generators are used for generating new items of content. Generators can be used to create a tag or category index page dynamically. A good example of this is PaginationGenerator whose responsibility is to generate multiple pages around a set of items like posts or any other collection (see #43 ).

A Generator must implement GeneratorInterface:

namespace Yosymfony\Spress\Core\ContentManager\Generator;

interface GeneratorInterface
{
    /**
     * Generate items.
     *
     * @param \Yosymfony\Spress\Core\DataSource\ItemInterface $templateItem The template item where generator was declared.
     * @param array                                           $collecions   An array with the collection name
     *                                                                      as a key and collection's item as value.
     *
     * @return Yosymfony\Spress\Core\DataSource\ItemInterface[]
     */
    public function generateItems(ItemInterface $templateItem, array $collecions);
}

Generators are performed just after Data Sources are loaded.

How to use a generator?

The starting point of a generator is a template file. e.g: index.html

---
generator: dummy

---
Template body...

Prior template will be passed as an argument to generateItems method of GeneratorInterface and this one would be used for generating new items.

Built-in generators

  • Pagination generator.
  • Taxonomy generator. See #57

@yosymfony yosymfony added this to the Spress 2.0.0 alpha1 milestone Aug 4, 2015

@yosymfony yosymfony self-assigned this Aug 4, 2015

@lury

This comment has been minimized.

Copy link
Contributor

lury commented Aug 29, 2015

👍

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