Skip to content

Instantly share code, notes, and snippets.

@johannessteu
Created November 25, 2014 08:53
Show Gist options
  • Save johannessteu/d573ce2d7e64754f8eb0 to your computer and use it in GitHub Desktop.
Save johannessteu/d573ce2d7e64754f8eb0 to your computer and use it in GitHub Desktop.
Use EelExpressions to filter Nodes in PHP
/**
* @var SiteRepository
* @Flow\Inject
*/
protected $siteRepository;
/**
* @var \TYPO3\Neos\Domain\Service\ContentContextFactory
* @Flow\Inject
*/
protected $contentContextFactory;
/** ---------------------------------------- */
/** @var \TYPO3\Neos\Domain\Model\Site $site */
$site = $this->siteRepository->findOnline()->getFirst();
/** @var ContentContext $context */
$context = $this->contentContextFactory->create(array("currentSite" => $site));
/* Will be an instance of \TYPO3\Eel\CompilingEvaluator */
$eelEvauator = $this->objectManager->get('TYPO3\Eel\EelEvaluatorInterface');
/**
* Don't forget to provide an array with all context variables like "site" in
* this example
*
* @var \TYPO3\Eel\FlowQuery\FlowQuery $nodes
*/
$nodeCount = \TYPO3\Eel\Utility::evaluateEelExpression('${q(site).children("main").count()}', $eelEvauator, array("site" => $context->getCurrentSiteNode()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment