1. Go to this page and download the library: Download smic/webcomponents library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
smic / webcomponents example snippets
namespace Acme\MyExt\Components;
use Sinso\Webcomponents\DataProviding\ComponentInterface;
use Sinso\Webcomponents\Dto\ComponentRenderingData;
use Sinso\Webcomponents\Dto\InputData;
class MyContentElement implements ComponentInterface
{
public function provide(InputData $inputData): ComponentRenderingData
{
$record = $inputData->record;
$properties = [
'title' => $record['header'],
'greeting' => 'Hello World!',
];
return (new ComponentRenderingData())
->withTagProperties($properties)
->withTagName('my-web-component');
}
}
namespace Acme\MyExt\Components;
use Sinso\Webcomponents\DataProviding\ComponentInterface;
use Sinso\Webcomponents\DataProviding\Helpers\FileReferencesHelper;
use Sinso\Webcomponents\DataProviding\Traits\Assert;
use Sinso\Webcomponents\Dto\ComponentRenderingData;
use Sinso\Webcomponents\Dto\InputData;
use TYPO3\CMS\Core\Resource\FileReference;
class Image implements ComponentInterface
{
use Assert;
public function __construct(
private readonly FileReferencesHelper $fileReferencesHelper,
) {}
public function provide(InputData $inputData): ComponentRenderingData
{
$record = $inputData->record;
$image = $this->fileReferencesHelper->loadFileReference($record, 'image');
// rendering will stop here if no image is found
$this->assert($image instanceof FileReference, 'No image found for record ' . $record['uid']);
return (new ComponentRenderingData())
->withTagProperty('imageUrl', $image->getPublicUrl())
->withTagName('my-image');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.