Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non blade files #50

Closed
ZebTheWizard opened this issue Jul 27, 2023 · 2 comments
Closed

Support non blade files #50

ZebTheWizard opened this issue Jul 27, 2023 · 2 comments

Comments

@ZebTheWizard
Copy link

ZebTheWizard commented Jul 27, 2023

There appears to be an API exposed for using Folio with a custom response Folio::renderUsing. However, if I do something like the following to render components with Inertia, it only works when I have the same directory structure in the default views/pages folder.

Folio::renderUsing(function (Request $request, MatchedView $matchedView) {
    $path = Str::between($matchedView->relativePath(), '/', '.blade.php');
    return Inertia::render($path, $matchedView->data);
});
Folio::route(resource_path('views/pages'), middleware: [
    '*' => [
        //
    ],
]);

example directory structure that successfully renders svelte components using Inertia:

/
└── resources
    ├── views
    │   └── index.blade.php
    │       └── users
    │           ├── [User].blade.php
    │           └── index.blade.php
    └── js
        └── Pages
            └── index.svelte
                └── users
                    ├── [User].svelte
                    └── index.svelte

ideally we could modify the resource path and add a value in a config file or in the service provider to tell Folio to search for svelte files instead of blade files so we could have the following directory structure instead:

/
└── resources
    └── js
        └── Pages
            └── index.svelte
                └── users
                    ├── [User].svelte
                    └── index.svelte

The setup could look something like this:

Folio::extension('svelte');
Folio::renderUsing(function (Request $request, MatchedView $matchedView) {
    return Inertia::render($matchedView->relativePath(), $matchedView->data);
});
Folio::route(resource_path('js/Pages'), middleware: [
    '*' => [
        //
    ],
]);
@ZebTheWizard
Copy link
Author

ZebTheWizard commented Jul 27, 2023

see pr #51

@driesvints
Copy link
Member

Thanks @ZebTheWizard. Let's see how your PR goes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants