The following is not using Umbraco Engage; it uses the out-of-the-box segment services available in v16 and v17.
I’ve implemented my own ISegmentService. I also have an IContentFinder implementation. The content finder is setting the request.SetSegment(...) before the request.SetPublishedContent call. Using the standard @Model.MyProperty I get the correct content for the chosen segment, all working as expected behind the scenes and displaying the correct content.
However, there are times I would like to change the logic in the view based on the current segment Does anyone know how I can get the alias of the current segment in the razor view? I feel like I must be missing something obvious
I am injecting the segment using request.Segment(…) in a content finder and in Ken’s blog post he is injecting the segment using the VariationContextAccessor in middleware.
And then it clicked, I could consume the VariationContextAccessor in my Razor view. A quick test and I have my segment alias…