dijkr / Copia

Laravel-project with CMS
0 stars 0 forks source link

Handling a CMS-partial for multiple routes #23

Open dijkr opened 1 year ago

dijkr commented 1 year ago

{{ partial:banner_cat }} is loaded within two views. Meaning two different routes. Meaning the CMS will only display the CMS-banner when using /categorie/{category:slug} this route at the moment. It won't respond to /product/{product:slug}. Both routes need the same partial.

The not so nice solution would be to create a new collection. And then create another Antlers-view that uses that collection. The partial doesn't need to change, but every product then need to set the category-banner. That is a lot of work and also doesn't make sense.

The best solution is to make the partial indepentent. I can see to obstacles:

The question is, should the category-data be indepentent from the back-end already, or should there be a solution with Antlers to catch this issue?

Check out https://github.com/dijkr/Copia/issues/16 to research the origin of this problem.

dijkr commented 7 months ago

I want the banner partial showing the banner for the category the product has a relation with. Right now, the banner only works when the route for a category is handled. This banner partial checks if the the second part of the url match something set at the CMS. Of course this second part is a name of a category -> {{ collection:categorien :slug:is="segment_2" }}. Whenever a product is shown, the second part of the URL is a product.

dijkr commented 7 months ago

Solved

  1. Controller gets data and stores it to $categorySlug
    return View::make('producten')
            ->layout('layout')
            ->with(['groupedProducts' => $groupedProducts,
                'category' => $category,
                'categorySlug' => $categorySlug,
            ]);
  2. View fetch the data into a URL <a href="/{{ categorySlug }}/{{ slug }}">
  3. Route used the Route::get('/{category:slug}/{product:slug}', [ProductController::class, 'showProduct']);]
  4. php artisan route:clear