Site Logo
Looking for girlfriend > Russian > Episerver get friendly url from contentreference

Episerver get friendly url from contentreference

Home About Us Contact Us. EpiServer - get absolute friendly url for given culture for page - episerver I've a following setup in my Manage Websites panel General Url is set to alloy. So for Search page I want to get absolute friendly url in all languages. I use following code to get friendly url for page found on Anders G.

SEE VIDEO BY TOPIC: Episerver CMS 9 tutorial with abpentucole.com mvc 5 och twitter bootstrap 3 part 1

Content:
SEE VIDEO BY TOPIC: EpiServer - Setting page title / meta description

Episerver Search & Navigation

I was really trying to avoid blogging about any more custom properties, things related to PropertyList or Episerver editor UI customization. However, I felt like digging into how easy or hard it would be to show friendly URLs for ContentReference and Url properties in a PropertyList, so I thought I may as well revisit all of the areas I was trying to avoid in one blog post!

I should also preface this post by saying that the code here is essentially a code experiment and I'm sharing it with that proviso. Finally, it's worth noting that Episerver don't actually support using the Url property in a PropertyList see this forum answer so it's probably worth keeping that in mind. Here Url is a Url property, and Link is a ContentReference, so our list item looks something like this:. To start with we run into the same issue as Grzegorz, in that we need to resolve friendly URLs before rendering as he explains, this is because the grid formatter doesn't work with Deferreds.

This is a bit of hassle because it means we need to resolve URLs from the backend for the initial load, and also from the frontend — when we close the dialog. As mentioned, we need a way to get our friendly URLs to the front end on initialization, this is what the IMetadataAware attribute is responsible for in this instance:. As you can see I tried to keep things as generic as possible, so it resolves the values of all Url and ContentReference properties, gets the friendly URLs and builds a dictionary of the mappings which is then passed to the frontend.

To avoid hard-coding the field names in the frontend the constructor also takes a string array which represents names of properties you'd like to show friendly URLs for. Json to convert the specified property names into camel case. This is very similar to Grzegorz's ExtendedCollectionEditor. Again, I based this heavily on the extendedFormatters.

I think for the most part it speaks for its self:. Aside from renaming some methods and some small tweaks the only major add is getContentUrlByPermanentLink which essentially just uses the Episerver PermanentLinkHelper.

This method just gets the content based on a permanent link, we then maintain the mappings in our urlMappings. To tie this all together we just need to tell Episerver to use our custom CollectionEditor, you can do this with a ClientEditorAttribute, meaning your property will now look like this:. Just to re-iterate, this code is something I put together for this blog post and comes with no quality guarantees.

Aside from that: feel free to go crazy with it! Great post Jake. However, it doesn't seem to work with the latest version of the CMS. Hey Jake.

Everything works except when I what to remove the link from the list. I click on the x for removing link and OK for closing the dialog but link is still in the list. Do you have any idea why? Andrej: I couldn't recreate your issue. Do you see anything in the console?

My feeling is that it shouldn't be related to the code above—but then I would say that! Let's start with the backend: The IMetadataAware attribute As mentioned, we need a way to get our friendly URLs to the front end on initialization, this is what the IMetadataAware attribute is responsible for in this instance: using System; using System.

Generic; using System. Linq; using System. Mvc; using EPiServer. Core; using EPiServer. ObjectEditing; using EPiServer. Web; using EPiServer. Routing; using Newtonsoft. Json; namespace EPiServer. Model as dynamic; if model?. OrdinalIgnoreCase ; foreach dynamic item in model. ContainsKey url. Add url. ToString , UrlResolver. ContainsKey contentLink. Add contentLink. IsAssignableFrom property. Link , nameof Item.

We do something very similar for the onExecuteDialog method where it was now necessary to create a DeferredList and wait on all responses. That's really it! The formatter Again, I based this heavily on the extendedFormatters.

Comments Peng: Thanks for that fix, I've updated the code to reflect it. Name E-mail.

Content URL, with or without shortcut?

By using our site, you acknowledge that you have read and understand our Cookie Policy , Privacy Policy , and our Terms of Service. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Using EpiServer 8. I've seen online posts that suggest the following:.

There is a bunch of articles how to get started with it in this mode. Default Alloy template allows you to quickly get content API up and running, but the default output result is far from being perfect for real case usage and usually requires customization. Cms dependency to default Alloy site.

Instead, rely on the helpers and extensions that EPiServer 7 provides. PageLink helper. For the text of the link, if you do not supply it with a text string, it will use the PageName property for the page or the Text property for a LinkItem object. You can also pass in route data information that can change the URL helpful when working with language branches or additional HTML attributes to add to the anchor tag.

Get external page urls on a multi-tenant multi-language Episerver site

I was really trying to avoid blogging about any more custom properties, things related to PropertyList or Episerver editor UI customization. However, I felt like digging into how easy or hard it would be to show friendly URLs for ContentReference and Url properties in a PropertyList, so I thought I may as well revisit all of the areas I was trying to avoid in one blog post! I should also preface this post by saying that the code here is essentially a code experiment and I'm sharing it with that proviso. Finally, it's worth noting that Episerver don't actually support using the Url property in a PropertyList see this forum answer so it's probably worth keeping that in mind. Here Url is a Url property, and Link is a ContentReference, so our list item looks something like this:. To start with we run into the same issue as Grzegorz, in that we need to resolve friendly URLs before rendering as he explains, this is because the grid formatter doesn't work with Deferreds. This is a bit of hassle because it means we need to resolve URLs from the backend for the initial load, and also from the frontend — when we close the dialog. As mentioned, we need a way to get our friendly URLs to the front end on initialization, this is what the IMetadataAware attribute is responsible for in this instance:.

How To Get The Friendly Url From Url Property in EPiServer 9

GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. Skip to content. Permalink Dismiss Join GitHub today GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. Sign up.

Sometimes it seems as if the hardest thing in Episerver is to retreive a proper external url of a PageData or ContentReference item.

Home About Us Contact Us. EpiServer - get absolute friendly url for given culture for page - episerver I've a following setup in my Manage Websites panel General Url is set to alloy. So for Search page I want to get absolute friendly url in all languages. I use following code to get friendly url for page found on Anders G.

How to get the friendly URL of a page in EPiServer CMS

In one of our project I had to refactor a code responsible for generating XML feed. The feed contains information like title, description and URL. There are three languages enabled for the site: English, Swedish and Norwegian.

It manages content. Having predictable methods for creating, modifying and retrieving content is crucial for a CMS. Most of the content can probably be accessed using some sort of URL. So given I have some sort of content, in this example a PageData object. PageData is the base of all pages in an Episerver site. We could try the LinkURL property.

Extension methods for obtaining ContentReference from LinkItem and Url

The method is made up to be as simple as possible to illustrate the how unit testing against a ContentArea can be done, which turns out to be non-trivial. The idea is to make it easier to find the post when googling for the subject matter or problems you might have. For the record, this code has been tested with EPiServer 7. GetContent in the ContentAreaHelper. GetItemNames method. So how do we do that? So first we need a IContentRepository that returns our content when queried.

Feb 8, - Using EpiServer , we need to get the "friendly" URL from a PageData object within a C# class. Without converting the URL, internal links look  EPiServer: Get friendly URL with language flag.

I'm having a problem when trying to render an Url from an Url property in my view. Problem is that I want the friendly URL either it's an internal nor an external link. PageUrl Model. ToString but for the internal link this only gives me the ID to the page.

In Episerver, we have a number of different ways of allowing content editors to add and set links on a website. In today's guide, I'm going to cover how to add an Episerver. Url property to a page-type or block, and then how to render that Url on your website so it uses the friendly Url and not the ugly internal Episerver identifier.

I am trying to get a friendly-url for a page of type ContentReference property in site settings in another page's controller. Debugging shows that neither the "urlResolver" nor the "SiteSettings. NewsletterSuccessPageRef" are null.

GetUrl with just a ContentReference as a parameter will return a url in the same context as the current request that is it the current request in onpageedit then the url will be in onpageedit format.

.

.

.

Comments: 3
  1. Memuro

    Useful phrase

  2. Kazirn

    I recommend to you to visit a site on which there are many articles on this question.

  3. Tojasar

    Excuse for that I interfere … But this theme is very close to me. Is ready to help.

Thanks! Your comment will appear after verification.
Add a comment

© 2020 Online - Advisor on specific issues.