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

Renderizer #48

Closed
yosymfony opened this Issue Aug 5, 2015 · 0 comments

Comments

Projects
None yet
1 participant
@yosymfony
Copy link
Member

yosymfony commented Aug 5, 2015

Renderizer are responsible for formatting content. This can be considered as a template engine. A renderizer must implements RenderizerInterface:

namespace Yosymfony\Spress\Core\ContentManager\Renderizer;

interface RenderizerInterface
{
    /**
     * Add a new layout.
     *
     * @param string $name       The name of the layout. e.g: id, path...
     * @param string $content    The content of the layout.
     * @param array  $attributes The attributes of the layout.
     */
    public function addLayout($name, $content, array $attributes = []);
    /**
     * Add a new include.
     *
     * @param string $name       $name The name of the include. e.g: id, path...
     * @param string $content    The content of the include.
     * @param array  $attributes The attributes of the include.
     */
    public function addInclude($name, $content, array $attributes = []);
    /**
     * Clears all templates registered.
     */
    public function clear();
    /**
     * Render a blocks of content (layout NOT included).
     *
     * @param string $name       The name of the content. e.g: id, path...
     * @param string $content    The content.
     * @param array  $attributes The attributes for using inside the content.
     *
     * @return string The block rendered
     */
    public function renderBlocks($name, $content, array $attributes);
    /**
     * Render a page completely (layout included).
     *
     * @param string $name           The name of the page. e.g: id, path...
     * @param string $content        The page content.
     * @param string $layoutName     The name of the layout.
     * @param array  $siteAttributes The attributes for using inside the content.
     *
     * @return string The page rendered.
     */
    public function renderPage($name, $content, $layoutName, array $siteAttributes);
}

Spress comes with a renderizer for Twig template engine: TwigRenderizer.

How to use a custom renderizer

Extends Spress with a new renderizer from a plugin is straightforward:

  • Suscribes to spress.start event and gets the EnvironmentEvent object received as an argument.
  • Adds your custom renderizer:
$environmentEvent->setRenderizer($myCustomRenderizer);

If you need to get the current renderizer: $renderizer = $environmentEvent->getRenderizer();

@yosymfony yosymfony self-assigned this Aug 5, 2015

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

@yosymfony yosymfony closed this Sep 15, 2015

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