laravel-modules icon indicating copy to clipboard operation
laravel-modules copied to clipboard

Just need some guidance

Open ap-coder opened this issue 3 years ago • 2 comments

So we using your module and we love them. But are looking for some clarification. We are trying to make them work stand alone as module and with a parent main site.

This way if the module is not added to the site it needs to be people can work on it. but if it is part of the parent then the main assets such as css and js come from parent.

My question is this. If the module cannot find say the main extends of say parent do we need to add a contidional for this or does it automatically fall back to a module specific blade file?

DEF Parent : referring to module inside live site.

Parent blade file from not inside module. We want this to be default

@extends('layouts.app')

This one is inside modules but we want it only used if not added to our parent site

@extends('Module::layouts.app')

If conditional I am not sure how to set one up and maybe you can help me.

@if(Module::has('Codegen') && Module::isEnabled('Codegen'))
  @extends('Module::layouts.app')
@else
  @extends('site.layouts.codegen')
@endif

As you can see if we use something like this it will be true in both Parent and Module. Not sure how to say if parent exists use parent else use module.

Any ideas or clarification would be great.

The reason we have them working this way is so we can have modules and work done outside out main site that we can drop in when its ready and not have to worry about updating the modules all the time if they are using the assets from the current site we have live. We want our production assets to be the overriding source and the module blade layouts to be secondary fall back.

ap-coder avatar Oct 10 '22 23:10 ap-coder

Forgive me if I'm not understanding you correctly. I believe you want to use a layout if a certain condition is true/false.

I'm not sure if you want to display the layout if one exists or if the module exists or both. But you can see if a layout exists using laravel's helper function: view()->exists('layouts.app')

For modules: view()->exists(codegen::layouts.app)

So you can do: @extends(view()->exists('layouts.app') ? 'layouts.app' : 'codegen::layouts.app')

I hope this points you in the right direction at least.

Osimba avatar Oct 11 '22 01:10 Osimba

Perfect answer to a weird question. thank you.

ap-coder avatar Oct 13 '22 22:10 ap-coder