jazzsessel's avatar

Module Independent Layout Engine

I'm currently struggleing with blade layout engine. Please let me explain: My application based on multiple modules, every module contain it's own template files, but if i want to add a special component from another module, i have to hard code it in the layout file. For example, i have two modules, a customer module and a subscription module and the subscription module has a special component, which display the subscription of the customer.

// module-customer/views/pages/customer.blade.php
...
<div>
    <subscription::user-subscription />
</div>
...

I want to prevent this hardcoding part!

I like the magento solution, which uses multiple XML files to combine this. In the customer module i define a "block" with a name like "customer-profile-details" and in the second module i can inject the "user-subscription" component in the already defined block.

// module-customer/views/pages/customer.xml
...
<block name=""customer-profile-details" class="\Customer\Components\Profile\Details" />
...
// module-subscription/views/pages/customer.xml
...
<reference name="customer-profile-details">
     <block name=""customer-subscription" class="\Subscription\Components\User" />
</reference>
...
// module-customer/views/components/profile/details.blade.php
...
<div>
    {{ $this->getChildBlock('customer-profile-details') }}
</div>
...

Does anybody know a solution like this or has maybe an alternative idea? I hope it is understandable :)

thanks a lot

0 likes
5 replies
Tray2's avatar

I don't understand the problem really, I mean components are supposed to be reusable.

If you create a form component for let's say a Book,

<x-book-form />

Inside that one you have something like.

<form method="POST" action="route('books.store')">
	<x-form-csrf />
	<x-form-input name="author"' :id="author" required />
	<x-form-input name="title"' :id="title" required />
	<x-form-submit />
</form>

Each of the form components are reusable and not connected to any particular module,

jazzsessel's avatar

thanks for your response. in your example, you're using two "modules", too. A form module and a book module. Let's say you have your book module and you wanna show details about the "User", which wrote the book and these details are just visible, if the user module is available / enabled. i want to hold the themes of every module independently.

Tray2's avatar

@jazzsessel Then you can use an if in your template.

@if($book->author)
	<x-author-information :author="$book->author" />
@endif
jazzsessel's avatar

@Tray2 that's clear to me, but i still link module author in module books, there is no independence of the modules. I think my problem is not so clear which means to me, there is no ready solution available and i have to develop one.

Thanks anyway

Please or to participate in this conversation.