[Flow] Own widgets - some questions.

Stephen Bungert stephenbungert at yahoo.de
Mon Jun 10 22:28:33 CEST 2013


I created a widgit to display certain records on my site. It's my first 
widget, and it works ok. What I want to know is:

1: why do I need to have a template for it?

The paginate widgit doesn't need it's own template, how do I get my 
widget too use the fluid template tags contained within it as its 
viewhelper (see my code below), the same way as the paginate widget 
SEEMS to?

2. It calls automatically the index action in my controller, how can I 
maybe specify the action to call - would be good as an argument in my 
widgets viewhelper.

Here is my widget viewhelper and controller and the template I need to make.

Viewhelper
---
<?php
namespace Vendor\Package\ViewHelpers\Widget;

/*                                                                        *
  * This script belongs to the TYPO3 Flow package "Vendor.Package".   	  *
  *                                                                        *
  * 
    */

use TYPO3\Flow\Annotations as Flow;

/**
  * A widgit for displaying genres.
  */
class GenresViewHelper extends 
\TYPO3\Fluid\Core\Widget\AbstractWidgetViewHelper {

	/**
	 * @Flow\Inject
	 * @var 
\Vendor\Package\ViewHelpers\Widget\Controller\GenresWidgetController
	 */
	protected $controller;

	/**
	 * Render this view helper
	 *
	 * @param string $as
	 * @return string
	 */
	public function render($as) {
		$response = $this->initiateSubRequest();
		return $response->getContent();
	}
}
?>
---



Controller
---
<?php
namespace Vendor\Package\ViewHelpers\Widget\Controller;

/*                                                                        *
  * This script belongs to the TYPO3 Flow package "Vendor.Package".   	  *
  *                                                                        *
  * 
    */

use TYPO3\Flow\Annotations as Flow;

/**
  * Genre widgit controller for the Vendor.Package package.
  */
class GenresWidgetController extends 
\TYPO3\Fluid\Core\Widget\AbstractWidgetController {

	/**
	 * @Flow\Inject
	 * @var \Vendor\Package\Domain\Repository\GenreRepository
	 */
	protected $genreRepository;



	/**
	 * Shows a list of genres.
	 *
	 * @return void
	 */
	public function indexAction() {
		$this->view->assign('contentArguments', array(
			$this->widgetConfiguration['as'] => $this->genreRepository->findTree()
		));
	}
}
?>
---


widget Template
---
<f:renderChildren arguments="{contentArguments}" />
---

Paginate widget doesn't seem to have any template, is my template really 
needed? Or can I change my code so that it just uses the child tags as 
it's template - a bit like the paginate widget seems to.

Thnaks for any help, flow is great!

Stephen.


More information about the Flow mailing list