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

Handling a CMS-partial for multiple routes #23

Open
dijkr opened this issue Jul 28, 2023 · 2 comments
Open

Handling a CMS-partial for multiple routes #23

dijkr opened this issue Jul 28, 2023 · 2 comments
Assignees

Comments

@dijkr
Copy link
Owner

dijkr commented Jul 28, 2023

{{ 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 ProductController has two functions, that fetch category-data. Just to add the data to product-related queries.
  • The URLs do not match, since both function will be called from seperate routes.

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 #16 to research the origin of this problem.

@dijkr dijkr added the Statamic label Jul 28, 2023
@dijkr dijkr self-assigned this Jul 28, 2023
@dijkr dijkr added the Antlers label Jul 28, 2023
@dijkr dijkr changed the title Handling a CMS-partial beeing used for multiple routes Handling a CMS-partial for multiple routes Jul 28, 2023
@dijkr
Copy link
Owner Author

dijkr commented Jan 10, 2024

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
Copy link
Owner Author

dijkr commented Jan 10, 2024

Solved

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

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

No branches or pull requests

1 participant