smic / webcomponents
Render Web Components
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:typo3-cms-extension
Requires
- ext-json: *
- typo3/cms-core: ^11.0 || ^12.0
This package is auto-updated.
Last update: 2024-05-03 13:20:41 UTC
README
This extension provides tools to render Web Components with TYPO3.
TypoScript based rendering
tt_content.tx_myext_mycontentelement = WEBCOMPONENT
tt_content.tx_myext_mycontentelement {
tagName = my-web-component
properties {
title.data = header
greeting = Hello World!
}
}
Generates the output:
<my-web-component title="This is the title from the content element record" greeting="Hello World!" ></my-web-component>
DataProvider based rendering
You can populate the web component with PHP:
tt_content.tx_myext_mycontentelement = WEBCOMPONENT
tt_content.tx_myext_mycontentelement.dataProvider = Acme\MyExt\DataProvider\MyContentElementDataProvider
<?php namespace Acme\MyExt\DataProvider; use Sinso\Webcomponents\DataProvider\DataProviderInterface; use Sinso\Webcomponents\DataProvider\Traits\ContentObjectRendererTrait; class MyContentElementDataProvider implements DataProviderInterface { use ContentObjectRendererTrait; public function provide(WebcomponentRenderingData $webcomponentRenderingData): WebcomponentRenderingData { $record = $webcomponentRenderingData->getContentRecord(); $properties = [ 'title' => $record['header'], 'greeting' => 'Hello World!', ]; $webcomponentRenderingData->setTagName('my-web-component'); $webcomponentRenderingData->setTagProperties($properties); } }
Convention: When the tag name is not set, the web component will not be rendered at all.