Pass custom Entity data into base.blade.php template

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
jgirard
Posts: 2
Joined: 23 Jun 2023, 09:34

Pass custom Entity data into base.blade.php template

Post by jgirard » 23 Jun 2023, 09:51

Hello,

I'm using Laravel package with Aimeos 2022.10

I'd like to know how to pass data from a custom Entity into my extension's base.blade.php template.
In this way, I can include this data in the header of my site so that it appears on all pages.
Please note that I'm not using a controller for this template.

I've seen some information about Decorators, but I'm not sure if this is what I need, or how to implement it.

Do you have any suggestions on how to accomplish this?

Thanks in advance

kdim95
Advanced
Posts: 207
Joined: 26 Aug 2022, 12:17

Re: Pass custom Entity data into base.blade.php template

Post by kdim95 » 23 Jun 2023, 11:54

Do you want to add something like contact information in the header/footer?

If it's something simple like that, I keep it in the site config (Settings).

All you need to do is add more form fields with new names like this name="item[locale.site.config][my-field]".

To add more fields, you need to override this file in your extension:
templates/admin/jqadm/settings/item.php

Then in base.blade.php:

Code: Select all

	@php
		$context = app( 'aimeos.context' )->get();
		$myconf = $context->config()->get( 'my-field' );
	@endphp
				
	<p>{{ $myconf ?? '' }}</p>
If you need to add something more complex, you should go with a component.

In base.blade.php add a @yield('your_component') where you want your component to appear.

Create the component:
https://aimeos.org/docs/2022.x/frontend ... omponents/

If you want to add your component to the home page, you need to override this file in your extension:
/views/catalog/home.blade.php

Add your component's section:

Code: Select all

@section('your_component')
	<?= $aibody['yourcomponent'] ?? '' ?>
@stop

jgirard
Posts: 2
Joined: 23 Jun 2023, 09:34

Re: Pass custom Entity data into base.blade.php template

Post by jgirard » 04 Jul 2023, 07:58

Hello,

Thanks for your feedback kdim95.

Your second solution worked. I created a component and added the section to my blade.php template.

Thanks again!

Post Reply