Create own custom block / subpart (SOLVED)

Questions around the TYPO3 integration and plugins
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
pla
Posts: 10
Joined: 06 Nov 2024, 11:05

Create own custom block / subpart (SOLVED)

Post by pla » 24 Mar 2026, 14:29

Hi,

I try to create my own custom block inside the filter template "body.php"

I am using TYPO3 13.4.23 and AIMEOS:
- aimeos/aimeos-core: 2024.10.15
- aimeos/aimeos-typo3: 24.10.5
- aimeos/ai-typo3: 2024.10.5
- aimeos/ai-client-html: 2024.10.7

I tried adding a block line into the file "templates/client/html/catalog/filter/body.php"

Code: Select all

// ...
			<?= $this->block()->get( 'catalog/filter/tree' ) ?>
			<?= $this->block()->get( 'catalog/filter/search' ) ?>
			<?= $this->block()->get( 'catalog/filter/subcategories' ) ?> // New block
			<?= $this->block()->get( 'catalog/filter/price' ) ?>
			<?= $this->block()->get( 'catalog/filter/supplier' ) ?>
			<?= $this->block()->get( 'catalog/filter/attribute' ) ?>
// ...
And I also added a new file inside the same directory "templates/client/html/catalog/filter/subcategories-body.php" according to the other block such as attributes-body.php, supplier-body.php in the hope this will work

Code: Select all

<?php

$enc = $this->encoder();

?>
<?php $this->block()->start( 'catalog/filter/subcategories' ) ?>
TEST SUBCATEGORIES BLOCK
<?php $this->block()->stop() ?>
<?= $this->block()->get( 'catalog/filter/subcategories' ) ?>
But it does not get rendered. So I searched the internet and the forum if there is a TypoScript configuration needed but I found nothing. The only thing I found was an example for blades in laravel which doesn't fit to me because I use TYPO3 and there was also no other configuration mentiod which I could adapt.

Has already created someone an own custom block?

Kind regards
Pla
Last edited by pla on 29 Mar 2026, 13:21, edited 2 times in total.

User avatar
aimeos
Administrator
Posts: 8734
Joined: 01 Jan 1970, 00:00

Re: Create own custom block

Post by aimeos » 27 Mar 2026, 15:00

The existing tree subpart (Catalog/Filter/Tree/Standard.php) already handles category filtering and might be what you actually want — it's commented out in the default config but can be enabled by simply adding 'tree' to the subparts config.

If you still want to register your own sub-part:
You only created a template file (subcategories-body.php), but that's not enough. The Aimeos client-html architecture requires three things for a new filter subpart:

1. You're Missing a PHP Component Class

Every subpart needs a PHP class that extends \Aimeos\Client\Html\Common\Client\Factory\Base. This class is responsible for:
- Populating the view with data (the data() method)
- Triggering the template render (inherited body() method)

Without it, no code ever renders your template, so the block is never populated.

You need something like:
src/Client/Html/Catalog/Filter/Subcategories/Standard.php

2. You're Missing the Subpart Registration in Config

The catalog filter component discovers its subparts from config key client/html/catalog/filter/subparts. The default list is:

// ext/ai-client-html/config/client.php
'subparts' => ['search', 'price', 'supplier', 'attribute']

"subcategories" is not in this list, so the main filter component never instantiates it. You need to add it via TYPO3 TypoScript config or your
extension's config.

3. Your Block Reference in the Main Template

You added $this->block()->get('catalog/filter/subcategories') to the main body.php — this part is correct in concept. But since steps 1 and 2
are missing, the block is always empty.

4. Your Template Has a Bug

Your template calls both $this->block()->stop() AND $this->block()->get() at the end. The get() at the bottom of a subpart template is the
standard pattern (it outputs the block content), but the block content is only useful when consumed by the parent template. Your subpart
template should just define the block; the parent template retrieves it.

What You Should Do

1. Create a PHP component class at Client/Html/Catalog/Filter/Subcategories/Standard.php with a data() method that fetches subcategory data
2. Register your subpart by configuring client/html/catalog/filter/subparts to include 'subcategories' (in TYPO3, this would be via TypoScript
setup)
3. Override the main filter template to include <?= $this->block()->get('catalog/filter/subcategories') ?>
4. Your template itself follows the existing pattern (block start/stop/get)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

pla
Posts: 10
Joined: 06 Nov 2024, 11:05

Re: Create own custom block

Post by pla » 29 Mar 2026, 13:21

Thank you very much! I already thought, that I miss some configuration in TypoScript but I would never have thought to implement a separate subpart class.

But I think the "bug" in my template isn't a bug because this is in all default templates as well. All of the subpart templates like search, supplier, attributes, ... have this structure where the subpart gets started, stopped and then the get() method is called immediately after stopping.

pla
Posts: 10
Joined: 06 Nov 2024, 11:05

Re: Create own custom block / subpart (SOLVED)

Post by pla » 30 Mar 2026, 07:55

One more question regarding blocks/subparts. Is this a special thing for the filter plugin or can this also be done for e.g. the list or detail view by adding the TypoScript config, subpart class and template?

For Example:

TypoScript:

Code: Select all

plugin.tx_aimeos {
	settings {
		client.html.catalog {
			lists {
				subparts {
					0 = tree
				}
			}
		}
	}
}
Subpart class in EXT:my_extension/Resources/Private/Extensions/aimeos/src/Client/Html/Catalog/Lists/Tree/Standard.php

Code: Select all

namespace Aimeos\Client\Html\Catalog\Lists\Tree;

class Standard
	extends \Aimeos\Client\Html\Common\Client\Factory\Base
	implements \Aimeos\Client\Html\Common\Client\Factory\Iface {

	public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], ?string &$expire = null ) : \Aimeos\Base\View\Iface {
		return parent::data( $view, $tags, $expire );
	}
}
And the template EXT:my_extension/Resources/Private/Extensions/aimeos/templates/client/html/catalog/lists/tree-body.php

Code: Select all

<?php $this->block()->start( 'catalog/lists/tree' ) ?>
CATALOG LISTS TREE SUBPART/BLOCK
<?php $this->block()->stop() ?>
<?= $this->block()->get( 'catalog/lists/tree' ) ?>
As well as the call of the block in the main lists template EXT:my_extension/Resources/Private/Extensions/aimeos/templates/client/html/catalog/lists/body.php

Code: Select all

<?= $this->block()->get( 'catalog/lists/tree' ) ?>
Because that is what I tried and unforunately it doesn't work. Now I don't know if I am missing something again or if it just doesn't work because its a special filter thing.

User avatar
aimeos
Administrator
Posts: 8734
Joined: 01 Jan 1970, 00:00

Re: Create own custom block / subpart (SOLVED)

Post by aimeos » 01 Apr 2026, 07:59

Custom subparts only work for components that explicitly implement the subparts mechanism — and the catalog list and detail components do not support it.

Components that support subparts (like Catalog\Filter\Standard) have:
- A $subPartPath property (e.g., 'client/html/catalog/filter/subparts')
- A $subPartNames array listing default subparts
- A getSubClientNames() override that reads from config
- body()/header() methods that iterate $this->getSubClients()
- Templates that render each block via $this->block()->get('catalog/filter/tree') etc.

Catalog Lists and Detail do NOT have any of this. They extend Catalog\Base and use the default getSubClientNames() from Client\Html\Base which returns an empty array. They render a single monolithic template with data prepared in data() — no subclient iteration happens.

So it doesn't work because it's not just a "filter thing" by accident — Lists and Detail were intentionally designed without subpart support. Adding a custom subpart via config won't do anything because those components never look for or render subclients.

To add custom content to list/detail views, you'd need to either:
1. Override the template directly
2. Override the entire component class to add subpart support (adding $subPartPath, $subPartNames, getSubClientNames(), and subclient iteration in body()/header())
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

pla
Posts: 10
Joined: 06 Nov 2024, 11:05

Re: Create own custom block / subpart (SOLVED)

Post by pla » 03 Apr 2026, 13:04

Thank you very much for your answer even though this is only an additional side question and giving me the needed hints achive it if I really want to do it.

I appreciate it a lot!

Post Reply