11

I need to create a link to an item in a different version than the currently active.

Is this possible through the General Link field or the RTE Sitecore Link?

Example

I am currently viewing http://mysite/somepage. I would like to link to http://mysite/en-us/some(other)page (language is resolved through URL in this scenario).

UPDATE

The requirement is that the editor should be able to link to an item in a different language.

  • Lots of answers that make sense below, but curious what you ended up doing? – Jeroen Sep 30 '17 at 1:13
7

The out of the box links don't specify language at all, so there is no way with an internal item reference to specify a specific language. The link is tied at the item level, not the version. Similarly, you can't directly link to a specific version of the content in the current language.

When invoked, the LinkManager uses the current context language for building the URL in a Rich Text field from the internal link. If you want to override this behaviour, you'll likely have to do the following:

  1. Add two fields on your content: one for the link, and one for the target language
  2. Write custom logic to output the link field and use the selected target language as a parameter for the LinkManager URL options.

NOTE: If you are using display name for your URLs, you might have to load the item in the target language and pass that target item into the LinkManager as your different languages might be outputting different URLs. If you only use the Sitecore.Context.Item for the parameter you will always get the path for the current language, and not the target one.

| improve this answer | |
3

I don't think there's an out of the box way to do this.

When I've had to do it previously - I've linked to a stub item which contains the link and the language however that's not really good for content editors (so best for content items which are configured by admins etc.

You could look at adding a list of languages as css classes (or something you can set on the link properties) and pick that up when the LinkManager gets to Url. Or something like that. Seems like a bit of a fudge tbh.

If you want a nicer solution for the content editor, you could add your own buttons to the RTE: Like this guy did and get the user to select the content item and language - generating the link with the language set (you'd have to test this to ensure LinkManager generates the link you want - if not - you'll need some customisation there as well).

| improve this answer | |
2

An out-of-the-box solution with no drawbacks is not available. Next to some things already mentioned here, you could also ask your editors to define the language in the querystring. When adding a link in a general link field you have the option (after selecting the item) to add the querystring. If they would put "sc_lang=xx" with xx the desired language code, that should generate a link to the page in that language. But again a drawback as this will not generate seo friendly links.. (and you need to make sure you have canonical urls on your pages then).

| improve this answer | |
0

Either by using General Link field or by using RTE Sitecore Link, you can manually type the url you want to be linked.

| improve this answer | |
  • I would like the link to be handled dynamically, so that editors should not type internal links manually. – Kasper Gadensgaard Oct 4 '16 at 12:28
-2

Sorry if I misunderstand your question - but if you are using the LinkManager.GetItemUrl() method, and you want to generate a link to an item in a different language you can use the Language attribute of the Sitecore.Links.UrlOptions class which you can optionally pass in to the GetItemUrl() method.

The UrlOptions class will also let you determine how you embed the language in the URL.

See this blog for more information https://sitecorejohn.wordpress.com/2008/11/23/manipulating-sitecore-links/

| improve this answer | |
  • No, I need the editors to be able to link to an item in a different language, so I am not looking for a code/configuration solution. I have updated the question accordingly. – Kasper Gadensgaard Oct 4 '16 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.