This one is to introduce an approach for getting public URL of a Sitecore media item inside Sitecore. As you all know in large setups the CM and CD are separated so it’s not always easy to know or guess what the public domain is especially for multisite setups. With user friendly public url, the user can copy the link and share it around easily.
Assumptions
- creating a new Sitecore field Media Public Url Picker which has a link menu Get Public Url
- clicking on Get Public Url link, a pop-up is displayed with a textbox contains the public URL which is generated automatically
- modifying any Sitecore media base templates to add new Media Public Url Picker field (Ex: /sitecore/templates/System/Media/Unversioned/Image)
- modifying Sitecore media folder template (/sitecore/templates/System/Media/Media folder) to add a new field contains the domain portion, for instance:
- field name: PublicDomain
- field type: Single-line Text
- if the domain portion is NOT available in any recursive media folders of a media item, it will be fetched from the config file as default public domain
If that is the case, you may want to play with my Media Public Url Picker field.
How to install it
Download this one as a Sitecore package on Sitecore Marketplace or on Gitlab then install it to your Sitecore instance via Installation Wizard.
How to use it
- log into Sitecore, upload a media
- open the new media item, click on the template link
- you’re now in the template editor:
- select Builder tab
- add new field section Media
- add new field Public URL whose field type is Media Public Url Picker and set it as shared field as well
- click Save button (or Ctrl+S)
- back to that media item editor, you would see the new field Public URL has a link menu Get Public Url then click on that link, a pop-up with public URL should be displayed
- looks OK now, let’s try to replace the domain portion to your own one
- open \App_Config\Include\z.Vhs.MediaPublicUrlPickerField.config
- modify this one
Note: please repeat #2 and #3 for each media base templates such as Image, Audio, Document, File inside “/sitecore/templates/System/Media/Unversioned” and “/sitecore/templates/System/Media/Versioned” if necessary
Is there a way to specify the domain portion for a specific media folder so that this module is able to support multisite implementation?
Yes, there is (at least in my opinion). Please follow these steps below to set it up:
- log into Sitecore, open a media folder item and click on the template link
- you’re now in the template editor:
- select Builder tab
- add new field section Media
- add new field PublicDomain whose field type is Single-Line Text and set it as shared field as well
- click Save button (or Ctrl+S)
- open \App_Config\Include\z.Vhs.MediaPublicUrlPickerField.config
- add PublicDomain to this setting (Note: | is separator so that it’s able to play with multiple field name)
- edit any media folder item, you would see a new field PublicDomain and you’re able to enter a new domain
- open a child item of that media folder item, click one Get Public Url link to see a new public URL
Note: the logic is to manage to find out the domain portion in the nearest ancestor items if possible. If nothing is available, will use the default public domain in the config file.
Integration examples:
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!
Why shouldn’t I just add it to the File template (/sitecore/templates/System/Media/Unversioned/File) where all other templates are derived from?
LikeLike
yeah, why not? if you’re planning to apply for all kind of media items, it should be a good place 😀
LikeLiked by 1 person