a few days ago I started using TYPO3 8.7.7 and I created a small website using Fluid powered TYPO3 extensions. Now I want to create a custom content element that displays a few products that the editor can manage in the backend. In my extension I created a simple model for the products:
namespace Something\Products\Domain\Model;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
class Product extends AbstractEntity
{
protected $name;
protected $description;
public function __construct(string $name, string $description)
{ ... }
public function getName(): string
{ ... }
public function setName(string $name)
{ ... }
public function getDescription(): string
{ ... }
public function setDescription(string $description)
{ ... }
}
I also created a ProductRepository class that simply extends \TYPO3\CMS\Extbase\Persistence\Repository.
In EXT:something/Configuration/TCA/tx_product.php
I have the following definition:
return [
'ctrl' => [
'title' => 'Products',
'label' => 'name'
],
'columns' => [
'name' => [
'label' => 'Name',
'config' => [
'type' => 'input',
'eval' => 'trim,required',
],
],
'description' => [
'label' => 'Description',
'config' => [
'type' => 'text',
'eval' => 'trim,required',
],
],
],
'types' => [
'0' => ['showitem' => 'name, description'],
],
];
Adding and editing products is working great in Web->List Module. I store them in a folder in the page tree called Products.
My goal is it to create a content element called Products to a page in an arbitrary column. The template in the frontend should display a list of products.
I would expect something like this in my EXT:something/Resources/Private/Template/Content/Product.html
<div xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
xmlns:flux="http://typo3.org/ns/FluidTYPO3/Flux/ViewHelpers"
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers">
<f:layout name="Content"/>
<f:section name="Configuration">
<flux:form id="newsitem" options="{group: 'Unicontrol'}">
<flux:field.input name="settings.headline" required="true"/>
</flux:form>
</f:section>
<f:section name="Main">
<ul>
<f:for each="{products}" as="product">
<li>{product.name}</li>
</f:for>
</ul>
</f:section>
</div>
Now I don't know how I can do that. I think I need a controller class but I can't figure out how to connect it with my Fluid powered TYPO3 Templates/Partials. Can anyone help me to find a way to realise this?
Thanks in advance and have a nice day.
EDIT:
My current CE template looks like this now:
<div xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
xmlns:flux="http://typo3.org/ns/FluidTYPO3/Flux/ViewHelpers"
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers">
<f:layout name="Content"/>
<f:section name="Configuration">
<flux:form id="products" options="{group: 'Unicontrol'}">
<flux:field.relation name="settings.relation" table="tx_products_domain_model_product"
transform="TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage<Something\\Products\\Domain\\Model\\Product>"
multiple="true"/>
</flux:form>
</f:section>
<f:section name="Main">
<ul>
<f:for each="{settings.relation}" as="product">
<li>{product.name}</li>
</f:for>
</ul>
</f:section>
</div>
I can now select one product of my list in the CE but in the frontend it only displays one element, the element I selected in the backend. It doesn't matter if I escape the slashes or not.