Example Route

You can create your own routes and use them for Ajax scripts, api's, external content or other things. Neos is not bound to the backend editor and your own routes would be a first step to a website that uses the repositories of Neos without using Neos 🥴

To see an example you can visit this url: https://www.neos.arsors.de/exampleRoute


Look what's behind it:

-
  name: 'Custom Route Example'
  uriPattern: 'exampleRoute'
  defaults:
    '@package':    'Arsors.Neos'
    '@controller': 'ExampleRoute'
    '@action':     'simplePHP'
    '@format':     'html'

<?php
namespace Arsors\Neos\Controller;

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;

use Neos\Eel\FlowQuery\FlowQuery;

class ExampleRouteController extends ActionController
{

/**
* @Flow\Inject
* @var Neos\ContentRepository\Domain\Service\ContextFactoryInterface
*/
protected $contextFactory;

/**
* @Flow\Inject
* @var \Neos\Flow\Security\Context
*/
protected $securityContext;

public function simplePHPAction()
{

// Get Context and from Context RootNode
$context = $this->contextFactory->create();
$node = $context->getRootNode();

// Init variable
$result = [];

// Find all Pages
$items = (new \Neos\Eel\FlowQuery\FlowQuery([$node]))
->find('[instanceof Arsors.Neos:Page]')
->get();

// Loop trough all Pages and get some Data
foreach ($items as $item) {
$result[] = $item->getNodeData()->getProperty("title")." was last edited ".$item->getNodeData()->getLastModificationDateTime()->format("d/m/Y")." at ".$item->getNodeData()->getLastModificationDateTime()->format("H:i:s");
}

// Assign variable to view (see HTML-Template)
$this->view->assign('results', $result);

}

}

<ul>
<f:for each="{results}" as="result">
<li>{result}</li>
</f:for>
</ul>
Last cache from 2020-10-06 at 08:27:56 (Example Eel Helper)