OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.35k stars 2.37k forks source link

Taxonomies: Autoroute Parents & Localization #4826

Open LMSSonos opened 4 years ago

LMSSonos commented 4 years ago

I have issues/questions regarding autoroute and taxonomies. In my example I have a taxonomy field OfferType which is the Taxonomy field. In my case I also can only select a leave and it's mandatory. I have configured a pattern like following

{{ContentItem.Content.LocalizationPart.Culture}}/{{ ContentItem.Content.Offer.OfferType.TermContentItemIds[0] | inherited_terms: ContentItem.Content.Offer.OfferType.TaxonomyContentItemId | reverse | join: "/" }}/{{ ContentItem.DisplayText | slugify }}

This works as expected.

First questions: Is this the right way to do this? How can I slugify the Taxonomy path? By simply adding slug it will join the array and I lose the / in the path

Second quesiton: How do I localize the taxonomy values?

hishamco commented 4 years ago

/cc @jptissot

sebastienros commented 4 years ago

How can I slugify the Taxonomy path? By simply adding slug it will join the array and I lose the / in the path

I don't understand this one, can you share some details?

LMSSonos commented 4 years ago

Sorry for not beeing clear. Let's assume I have the following Taxonomy for the Offers

Now, if I run for the Offer with the Taxonomy Sub the following code

{{ ContentItem.Content.Offer.OfferType.TermContentItemIds[0] | inherited_terms: ContentItem.Content.Offer.OfferType.TaxonomyContentItemId | reverse | join: "/" }} I get the result "Main/Sub"

If I want to slugify the names for the url usage in autopath I added following rule {{ ContentItem.Content.Offer.OfferType.TermContentItemIds[0] | inherited_terms: ContentItem.Content.Offer.OfferType.TaxonomyContentItemId | reverse | join: "/" | slugify }} Now it returns me "main-sub". This is as expected but not as wanted, I wanted to get "main/sub"

so next try is to use as following {{ ContentItem.Content.Offer.OfferType.TermContentItemIds[0] | inherited_terms: ContentItem.Content.Offer.OfferType.TaxonomyContentItemId | reverse | slugify | join: "/" }} Now what happens it returns "mainsub". The slugify seems to join the array from reverse.

jtkech commented 4 years ago

Maybe {{ ... | reverse | join: "/" | downcase }}

LMSSonos commented 4 years ago

@jtkech thanks, your case works for my example, but if you have special characters you need slugify which does more than downcase

as example

then you want to generated main-a/sub-a

petrouchka commented 4 years ago

Since the taxonomy content type already have the alias part, and the alias part normally slugified from the content item when creating a taxonomy. So how about recursively get the alias by liquid map filter then reverse & join?

example: {{ ContentItem.Content.LocalizationPart.Culture }}/{% if ContentItem.Content.Offer.OfferType.TermContentItemIds.size > 0 %}{{ ContentItem.Content.Offer.OfferType.TermContentItemIds.first | inherited_terms: ContentItem.Content.Offer.OfferType.TaxonomyContentItemId | map: "Content" | map: "AliasPart" | map: "Alias" | reverse | join: "/" }}/{% endif %}{{ ContentItem.DisplayText | slugify }}

New to orchard core, please correct me if I'm wrong.

sebastienros commented 4 years ago

does slugify work instead of downcase from @jtkech 's example?