enhancement

Playing with site-specific Sitecore Link Manager

In real Sitecore projects, you may have to deal with some special requirements such as ensuring to have a slash at the end of the links which are normally generated by Link Manager. Technically, it should be an easy one by implementing a string extension method like this:

clp_1

 

However, there are many places need to be updated for using EnsurePostfixSlashForLink above. In addition, the requirements are different probably for every single site so I think that we should play with site-specific Link Manager. The main purpose is to have a chance to use our own implementation and define additional URL option(s) if necessary.

Personally, I love the approach of my fellow Sitecore MVP Kamruz Jaman https://jammykam.wordpress.com/2017/09/22/switching-link-manager/

Yeah, I know that I’m a lazy developer but I still want to make my hand dirty by using ILSpy for decompiling Sitecore.Kernel.dll in order to learn how to get the value of an  attribute on a Link Provider configuration.

clp_2.png

As a consequence, I have my own Sitecore package (thanks for your sponsor Kamruz Jaman) so that I can play with it on every single Sitecore project.

 

This slideshow requires JavaScript.

How to install it

  • Use SIM to setup a new Sitecore 8/9 instance. For a better practice:
    • add a host name mvcsite.local
    • download this Sitecore package (sample site) and install it to your Sitecore instance via Installation Wizard
    • hopefully, you can see something like this
    • This slideshow requires JavaScript.

  • Download the module as a Sitecore package on Gitlab then install it to your Sitecore instance via Installation Wizard

How to use it

  • open \App_Config\Include\MvcSite\MvcSiteDefinition.config
  • add a new site property:
    • linkProvider=”vhs”
    • clp_7
  • access http://mvcsite.local/, you would see this
    • clp_8
  • now we try to remove the postfix slash
    • open \App_Config\Include\z.Vhs.SiteSpecificLinkProvider.config
    • set ensurePostfixSlash=”false”
    • clp_10.png
    • access http://mvcsite.local/, you would see this
    • clp_11

Note: if you specify non-existent link provider via site definition, the fallback will be the default link provider (in this case is sitecore)

  • clp_12.png

 

Not Good Enough? Please feel free to download the source code and add your own enhancements if necessary.


Got issues?

Please send your issues (with screenshots if possible) to viet.hoang.sitecore@gmail.com so that I have a chance to understand your problem and be able to suggest the solution.

Happy Sitecore Coding!

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.