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 segments from querystring in preview #17819

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

kjac
Copy link
Contributor

@kjac kjac commented Dec 16, 2024

Prerequisites

  • I have added steps to test this contribution in the description below

Description

When previewing documents, one can appy a culture parameter to the querystring to change the culture being previewed. This is what ultimately makes the language selector work in preview mode.

For some odd reason, segments have never been supported in the same way, which is what this PR fixes.

Note that only the "by ID" and "by key" content finders support this kind of context switching by means of the querystring ... the default content finder (for resolving via route) does not.

Testing this PR

  1. Configure a few languages.
  2. Setup a page using a template that prints out the current variation context (see example below). It does not need to be a variant page for this to work.
  3. Preview the page.
  4. The preview frame (UI) does not yet support segments, so you'll have to exit the preview frame by clicking this button:
    image
  5. Now verify that you can change culture and segment by using the culture and segment querystring parameters, respectively.

Template example

@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@inject IVariationContextAccessor VariationContextAccessor;
@{
    Layout = null;
    var context = VariationContextAccessor.VariationContext ?? throw new InvalidOperationException("No variant context found!");
}
<html lang="en">
<body>
<h1>@Model.Name</h1>
<ul>
    <li>Culture: @context.Culture</li>
    <li>Segment: @context.Segment</li>
</ul>
</body>
</html>

Copy link
Member

@Zeegaan Zeegaan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm 🚀

@Zeegaan Zeegaan merged commit 7a3862e into v15/dev Dec 17, 2024
26 of 27 checks passed
@Zeegaan Zeegaan deleted the v15/feature/segments-from-url branch December 17, 2024 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants