This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Wouter
Wouter

I would like to use LScache. For this I installed the lscache package from litespeed with composer. After I did that I tried to create a plugin to modify the route so that it could be cached.

I used this example as a starting point. This shows that the caching works if I put the following in routes.php:

Route::any('/tester', 'Cms\Classes\CmsController@run')->where('slug', '(.*)?')->middleware('lscache:max-age=300;public,web');

Now I'm trying to get the route so that I can also cache cms pages and not only the root page. When i now open domain.com/tester it shows me the root page and not the cms page i have created for /tester.

I've read about the routes in octobercms and Laravel but I didn't find the answer or I didn't get it.

Is there an example available somewhere to do something similar or do I have a completely wrong plan and is it better way to realize this?

daftspunky
daftspunky

Hi Wouter

It is possible to complete override the CMS route by defining it inside the App::before method. An example of this can be found in the RainLab Translate plugin, here is an excerpt:

App::before(function ($request) {

    // ...

    Route::any($locale, 'Cms\Classes\CmsController@run')->middleware('web');

    // ...

});

I hope this helps

Wouter
Wouter

Hi Daftspunk,

This helps me a lot to make what I want!

Wouter
Wouter

I think I was too quick with my message that it would work. What is happening now is the same as the problem I had before. When I set

$locale = '/somepage';

Then not the right page wil be opened, its always the root / index page that will be opened. I can't find how I would return the route to any page.

daftspunky
daftspunky

Sorry, I was only providing some general guidance. The more specific code you may want to try is something like this:

Event::listen('cms.route', function () {
    Route::any('{slug?}', [\Cms\Classes\CmsController::class, 'run'])
        ->where('slug', '(.*)?')
        ->middleware('web')
    ;
});

There is actually a dedicated event for bypassing the cms routes called cms.route.

I hope this helps!

Wouter
Wouter

Hi Daftspunk,

Thx for your help!!

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.