Two different templates for one component

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Starpag
Posts: 9
Joined: 11 Nov 2020, 22:06

Two different templates for one component

Post by Starpag » 18 Nov 2020, 18:29

Hello! I need to implement two or more different views of catalog/filter component with same functionality.

As i found in docs:

Code: Select all

<component type>/<component name>/[<subpart name>[-<sub-subpart name>]-]{body,header}-<variant>.php
Seems like <variant> is what i need, but i don't sure about that and don't understand how to use.

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

Re: Two different templates for one component

Post by aimeos » 19 Nov 2020, 13:53

It depends a bit on your application environment (Laravel, Symfony or TYPO3).

In Laravel/Symfony, you need to set the configuration for the variant template in the controller action, e.g.:
https://aimeos.org/docs/2020.x/config/c ... plate-body

In TYPO3, you can configure the template per plugin instance in the TS-Config field.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Starpag
Posts: 9
Joined: 11 Nov 2020, 22:06

Re: Two different templates for one component

Post by Starpag » 19 Nov 2020, 20:52

Sorry, forgot to write, i use Laravel.

Oh, it's really difficult to understand docs. But i tried and it's now work or i doing something wrong.

Seems like that not what i need, but i'll tried anyway.

I added:
1. shop.php

Code: Select all

  'client' => [
        'html' => [
            'catalog' => [
                'filter' => [
                    'cache' => false,
                    'tree' => [
                        'standard' => [
                            'template-body' => 'catalog/filter/tree-body-menu',
                        ],
                    ],
                ],
            ],
         ],
       ],
2. Create copy of tree-body-standard.php with name tree-body-menu.php and some changes
3. Added <?= $aibody['catalog/tree'] ?? '' ?> where i need in Blade template file between section

But there is no changes in frontend at all.

As i understand, this will replace catalog/tree/template in whole site, but i need to save original one template and create new one with same functionality but with another template. Is that what i need?
Last edited by Starpag on 19 Nov 2020, 21:00, edited 1 time in total.

Starpag
Posts: 9
Joined: 11 Nov 2020, 22:06

Re: Two different templates for one component

Post by Starpag » 19 Nov 2020, 20:59

I just want to implement such simple think like Megamenu to header.
Something like this
Image

To implement this as i understand i need catalog/tree, but seems like it's overpowered for my case. Maybe i'm going wrong way?

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

Re: Two different templates for one component

Post by aimeos » 21 Nov 2020, 09:47

Your steps are correct, this should use your alternative template for the tree part of the catalog/filter component and the catalog/tree component provided you placed your template in your own extension at ./ext/<yourext>/client/html/templates/catalog/filter/tree-body-menu.php

Check, if it's not cached resp. disable caching for development:
https://github.com/aimeos/aimeos-laravel#hints

If it doesn't work for whatever reason, try to save your own template as
./ext/<yourext>/client/html/templates/catalog/filter/tree-body-standard.php

This will overwrite the default template.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Starpag
Posts: 9
Joined: 11 Nov 2020, 22:06

Re: Two different templates for one component

Post by Starpag » 21 Nov 2020, 12:22

For some reasons it's work if i named it tree-body-standard.php, but tree-body-menu.php not work.

Cache is disabled, yes. I will try further.

But as I understand it enforce all <?= $aibody['catalog/tree'] ?? '' ?> in whole site used new template, but how to determinate with <?= $aibody['catalog/tree'] ?? '' ?> which Variant of template -menu or -menu2 in different places?

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

Re: Two different templates for one component

Post by aimeos » 23 Nov 2020, 17:19

Starpag wrote: 21 Nov 2020, 12:22 For some reasons it's work if i named it tree-body-standard.php, but tree-body-menu.php not work.
Then, your configuration in your ./config/shop.php file isn't used. Can you please post your file (without credentials)?
Starpag wrote: 21 Nov 2020, 12:22 But as I understand it enforce all <?= $aibody['catalog/tree'] ?? '' ?> in whole site used new template, but how to determinate with <?= $aibody['catalog/tree'] ?? '' ?> which Variant of template -menu or -menu2 in different places?
It's not possible to distingusih in the Blade template which variant should be used. This can only be done by setting the configuration in the controller action.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Starpag
Posts: 9
Joined: 11 Nov 2020, 22:06

Re: Two different templates for one component

Post by Starpag » 24 Nov 2020, 13:59

Here my shop.php

Code: Select all

<?php

return [

    'apc_enabled' => false, // enable for maximum performance if APCu is availalbe
    'apc_prefix' => 'aimeos:', // prefix for caching config and translation in APCu
    'pcntl_max' => 4, // maximum number of parallel command line processes when starting jobs

    'routes' => [
    ],


    'page' => [
        // Docs: https://aimeos.org/docs/Laravel/Adapt_pages
        // Hint: catalog/filter is also available as single 'catalog/tree', 'catalog/search', 'catalog/attribute'
        'account-index' => ['account/profile', 'account/review', 'account/subscription', 'account/history', 'account/favorite', 'account/watch', 'basket/mini', 'catalog/session', 'locale/select'],
        'basket-index' => ['basket/bulk', 'basket/standard', 'basket/related'],
        'catalog-count' => ['catalog/count'],
        'catalog-detail' => ['basket/mini', 'catalog/stage', 'catalog/detail', 'catalog/session', 'locale/select'],
        'catalog-home' => ['basket/mini', 'catalog/home', 'locale/select', 'catalog/tree'],
        'catalog-list' => ['basket/mini', 'catalog/filter', 'catalog/lists', 'locale/select'],
        'catalog-stock' => ['catalog/stock'],
        'catalog-suggest' => ['catalog/suggest'],
        'catalog-tree' => ['basket/mini', 'catalog/filter', 'catalog/stage', 'catalog/lists', 'locale/select'],
        'checkout-confirm' => ['checkout/confirm'],
        'checkout-index' => ['checkout/standard'],
        'checkout-update' => ['checkout/update'],
    ],

    'admin' => [],

    'client' => [
        'html' => [
            'basket' => [
                'cache' => [
                    // 'enable' => false, // Disable basket content caching for development
                ],
            ],
            'catalog' => [
                'filter' => [
                    'cache' => false,
                    'tree' => [
                        'standard' => [
                            'template-body' => 'catalog/filter/tree-body-menu',
                        ],
                    ],
                ],
            ],
            'common' => [
                'template' => [
                    // 'baseurl' => public_path( 'packages/aimeos/shop/themes/elegance' ),
                ],
            ],
            'catalog' => [
                'selection' => [
                    'type' => [
                        'color' => 'radio',
                        'length' => 'radio',
                        'width' => 'radio',
                    ],
                ],
            ],
        ],
    ],

    'controller' => [],

    'i18n' => [],

    'madmin' => [
        'cache' => [
            'manager' => [
                 'name' => 'None', // Disable caching for development
            ],
        ],
        'log' => [
            'manager' => [
                'standard' => [
                    'loglevel' => 7, // Enable debug logging into madmin_log table
                ],
            ],
        ],
    ],

    'mshop' => [],


    'command' => [],

    'frontend' => [],

    'backend' => [],

];
This can only be done by setting the configuration in the controller action.
How can i do this? This is exactly what i want.

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

Re: Two different templates for one component

Post by aimeos » 26 Nov 2020, 11:26

These are the steps you need:

- Create your own Laravel controller in your ./app/Http/Controllers/ directory

- Copy the action from the Aimeos controller you want to have a different configuration, e.g. https://github.com/aimeos/aimeos-larave ... hp#L86-L96

- Use this to set the modified configuration:

Code: Select all

app('aimeos.context')->getConfig()->set('client/html/catalog/filter/tree/standard/template-body', 'catalog/filter/tree-body-menu');
- Add a route with your own controller that replaces the Aimeos standard route, e.g. one of https://github.com/aimeos/aimeos-larave ... #L183-L235
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply