leafsphp / leaf

🍁 The easiest way to create clean, simple but powerful web apps and APIs quickly
https://leafphp.dev
MIT License
1.11k stars 68 forks source link

blade module #265

Open andrew-m-p opened 3 days ago

andrew-m-p commented 3 days ago

Hello. This is not a bug I need info on using blade module.

I want to create components , where am I expected to put this in the app ?

app()->blade()->directive('datetime', function ($expression) { return "<?php echo with({$expression})->format('F d, Y g:i a'); ?>"; });

Can I create a component like this instead ? with alert.blade.php

Thanks in advance

andrew-m-p commented 3 days ago

Cannot get the example to work:

app()->blade()->directive('datetime', function ($expression) { return "<?php echo with({$expression})->format('F d, Y g:i a'); ?>"; });

Which allows you to use the following in your blade template:

Current date: @datetime(date())

It says ""Call to a member function directive() on null""

andrew-m-p commented 2 days ago

It is a bug I get "Call to a member function directive() on null"" The reason is that configure in\leaf\blade is not being called first to set $this->blade

andrew-m-p commented 2 days ago

Need to hack with a call to configure first before directive()

Leaf\Config::get("views.blade")->configure(AppConfig('views.path'), AppConfig('views.cachePath'));

andrew-m-p commented 1 day ago

Ended up using $blade = new Blade( AppConfig('views.path'), AppConfig('views.cachePath')); Then $blade->directive('selectlanguage',[GlobalHelpers::class,'selectlanguage']);

echo self::$blade->make('mycontroller', $data)->render();

Al least I could get the directive to work