Renaming a document that is attached to multiple pages
I may have a writer who needs to link a single PDF onto multiple pages (content nodes). Can we link that PDF in such a way, that if the writer ever needs to rename the PDF, the name also changes on all pages that have the PDF linked? Is this possible through Umbraco?
You've probably noticed if you make an anchor link, and choose 'link to file' and pick the pdf from the media section of Umbraco, then what is embedded inside the rich text area is
<a href="/media/1234/somename.pdf">My Pdf</a>
If the editor then replaces somename.pdf with somename2.pdf in the media section, that these links are NOT automatically updated.
They would need to be 're-inserted' into each rich text area to update the link.
If this is a common scenario, then a workaround is to create a new Macro, called InsertPDFLink, let it have a parameter of media picker type, and implement a macro partial view, to take the id of the picked media, and retrieve the PDF from the media section, writing out it's Url, if the file ever changes in the future, with this method, the Ids remain the same, and the updated Url is written out for the new file. You also have control over the markup being writted out, and so can put an
<i class="icon icon-document"></i>
in front of the link to indicate type.
and your macro partial would be something like this:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{ var mediaId = Model.MacroParameters["PdfFile"]; }
@if (mediaId != null)
{
@* Get all the media item associated with the id passed in *@
var mediaItem = Umbraco.TypedMedia(mediaId);
if (mediaItem!=null)
{
<p><i class="icon icon-document"></i><a href="@mediaItem.Url">@mediaItem.Name</a></p>
}
}
Renaming a document that is attached to multiple pages
I may have a writer who needs to link a single PDF onto multiple pages (content nodes). Can we link that PDF in such a way, that if the writer ever needs to rename the PDF, the name also changes on all pages that have the PDF linked? Is this possible through Umbraco?
Hi Kensley
You've probably noticed if you make an anchor link, and choose 'link to file' and pick the pdf from the media section of Umbraco, then what is embedded inside the rich text area is
If the editor then replaces somename.pdf with somename2.pdf in the media section, that these links are NOT automatically updated.
They would need to be 're-inserted' into each rich text area to update the link.
If this is a common scenario, then a workaround is to create a new Macro, called InsertPDFLink, let it have a parameter of media picker type, and implement a macro partial view, to take the id of the picked media, and retrieve the PDF from the media section, writing out it's Url, if the file ever changes in the future, with this method, the Ids remain the same, and the updated Url is written out for the new file. You also have control over the markup being writted out, and so can put an
in front of the link to indicate type.
and your macro partial would be something like this:
and the editor would see
regards
Marc
Thank you so much marc! I will play with this process shortly on my end and get back to you.
cool,
Editors also tend to appreciate this package:
https://our.umbraco.org/projects/backoffice-extensions/media-content-usage/
it tracks where a media item has been used!
Thanks again marc, I got both solutions working for me. Much appreciated.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion