https://twill.io logo
Twill packages
# ❓questions
j
Quick question about twill packages. it is extended with TwillPackageServiceProvider Normally i would need to boot for example my migrations: https://laravel.com/docs/9.x/packages#migrations $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); I see that TwillPackageServiceProvider takes care of a lot already if using a Capsule. Are views or components also taken care of with TwillPackageServiceProvider I see blocks and repeaters but i gues that's for the Twill CMS side not the frontend. Say i create a resources folder in my capsule where i add a component and some javascript, is that the only thing i need to boot in my service provider?
i
Yes anything Twill is auto registered or there is an helper in the provider to do so. For your own frontend stuff you need to boot it yourself indeed.
j
You guys keep making live easier 😛
i
Glad to hear that!
j
Hi, I have some difficulty figuring out what the directory structure should be for a package with twill blocks and repeaters.
I have in my package src/MyServiceProvider and resources/views/twill/blocks/ and resources/views/twill/repeaters but my controller inside my capsule is not able to find the blocks using BlockEditor::make()->blocks(['cookie-block']),
Now i found this explanation: Register a blocks directory. If a namespace is provided for the render, Twill will assume it to be under: NAMESPACE::site.blocks.BLOCK-NAME Given $this->loadViewsFrom(__DIR__ . '/../resources/views/site/blocks', 'package-name'); So if you have a block called “example” and you want your package to provide the preview. Your file should be in resources\views\site\blocks\example.blade.php. To make sure the end user can override the views, you should make them publishable: $this->publishes([ __DIR__ . '/../resources/views' => resource_path('views/vendor/PACKAGE-NAME'), ]); For me (__DIR__ . '/../resources/views/site/blocks' would be (__DIR__ . '/../resources/views/twill/blocks' for the blade files to add the fields to the singleton in the cms. But the blocks editor is not showing.
/../resources/views/site/block if im correct his is for the preview file and not the blade file for the fields
TwillBlocks::registerPackageBlocksDirectory(__DIR__.'/../resources/views/twill/blocks'); Seems to work 🙂
parent::registerBlocksDirectory(__DIR__.'/../resources/views/twill/blocks'); Even better