PhileCMS / Phile

A flat file CMS with a swappable parser and template engine.
https://philecms.github.io/
Other
257 stars 49 forks source link

[FEATURE] Added $folder parameter functions to pages #71

Closed estudiooka closed 10 years ago

estudiooka commented 10 years ago

Make page model more flexible adding $folder = CONTENT_DIR so it’s possible to select where start the page tree, useful for creating plugins.

NeoBlack commented 10 years ago

First thanks for your pull request. But I can't see the benefit, please can you explain why you need this change? Maybe give us some examples.

james2doyle commented 10 years ago

I can see this being useful for loading a bunch of markdown files from a plugins folder.

NeoBlack commented 10 years ago

+1 ok, nice idea, now I understand the benefit.

estudiooka commented 10 years ago

Sometimes I need a collection of .md, but I don't want then on my pages. So I made a quick plugin for collections using the page repository.

index.php define('CONTENT_DIR', ROOT_DIR . 'content/pages' . DIRECTORY_SEPARATOR);

plugin.php

public function on($eventKey, $data = null) {       
    if ($eventKey == 'template_engine_registered') {
        $collection = new Twig_SimpleFunction('collection', function ($folder) {
            return $this->getCollections($folder);               
        });
        $data['engine']->addFunction($collection);      
    }
 }
  private function getCollections($folder) {
       $this->pageRepository = new \Phile\Repository\Page();
       $collection = $this->pageRepository->findAll( NULL, ROOT_DIR. 'content/collections/'.$folder) ;  
    return $collection;         
 }
james2doyle commented 10 years ago

@NeoBlack is this ok to merge? I like it.