laravel / folio

Page based routing for Laravel.
MIT License
568 stars 46 forks source link

The shared variable in the `render` function can not be accessed between `@php` and `@endphp` directives #102

Closed mahmoudmohamedramadan closed 1 year ago

mahmoudmohamedramadan commented 1 year ago

Folio Version

1.1.0

Laravel Version

^10.10

PHP Version

^8.1

Description

I can not access the shared variable inside the new render function between @php and @endphp directives. Let me demonstrate with the next two examples of code

// The code example that @nunomaduro uses 

<?php
    use function \Laravel\Folio\render;

    render( function($view) {
        $post = ['title' => 'Welcome Render Method!'];

        return $view->with('post', $post);
    });
?>

 // The value of `title` is printed out successfully
<?php echo $post['title']; ?>

But when I use the previous code between @php and @endphp directives the Undefined variable $post error is triggered

@php
    use function \Laravel\Folio\renderWhen;

    renderWhen(true, function($view) {
        $post = ['title' => 'Welcome Render Method!'];

        return $view->with('post', $post);
    });
@endphp

@dd($post);

Steps To Reproduce

NULL

nunomaduro commented 1 year ago

@mahmoudmohamedramadan The render function should only be used within <?php tags.