You can use the related links if the files that you want to link to is external files. I am not sure that make the pdf documents a part of your content structure is the best solution.
But what you could do is create a pdf document type, on this document type use a media picker or a upload data type.
But if you just want to list files from a folder in the media library I would recommend you to use the media picker, on the page, and the select a folder from the media library, and loop through the folder and output the files.
@if (CurrentPage.HasValue("relateradokument"))
{
<ul>
var caseStudyImagesList = CurrentPage.CaseStudyImages.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
var caseStudyImagesCollection = Umbraco.Media(caseStudyImagesList);
foreach (var caseStudyImage in caseStudyImagesCollection)
{
//I want it to list the dokucment as links
<li><a href="@caseStudyImagesList" target="@caseStudyImagesCollection">@item.caption</a></li>
}
}
</ul>
}
relateradokument is the alias of the media picker.
I want it to list the dokuments as links, but not sure how to do it.
This snippet of code below should do it for you. Remember to change @item.Name if you want the link text to be another property.
@if (CurrentPage.HasValue("relateradokument"))
{
@* Get all the media item associated with the id passed in *@
var media = Umbraco.Media(CurrentPage.relateradokument);
var selection = media.Children("File");
if (selection.Any())
{
<ul>
@foreach (var item in selection)
{
<li>
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
}
}
@* Get all the media item associated with the id passed in *@
var media = Umbraco.Media(CurrentPage.relateradokument);
var selection = media.Children("File");
<ul>
@foreach (var item in selection)
{
<li>
<a href="@item.Url">tusvr</a>
</li>
}
</ul>
Did your page have a folder selected, in the media picker.
You could try break the code down piece for piece to see where it fails. And please check that the property alias of the property is "relateradokument"
Ah okay that´s where the problem is. With my code you will need to select a folder in the media library, and then the code will list all the items in this folder of the filetype file.
Please let me know if you only want to pick the a file and not a folder, and loop trough the files in the folder.
list items
I want to list links and document items on a list. For this purpose, I'm using Related Links and Multiple Media picker.
I want it to list the items that the user creates and if the user isnt creating the items, then i shouldn't display anything
This is what I've done so far:
The problem is that it doesn't show anything, even tho I've created several items on the back-office.
Help please
Hi Johan,
You can find the documentation for the related links data type, and how to get data out from it using dynamic or strongly typed Razor here: https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/related-links
And the multiple media picker documentation is available here https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Media-Picker
Hope this helps,
/Dennis
I tried the following:
note that "relateradlaenk" is the alias of the Related Link
I tried it, but but it still doesnt show any values even tho I've created them in the backoffice
Hi Johan,
Try this code below.
Hope this works,
/Dennis
Thank you Dennis, it's working!
Is it possible to link to documents (for example .pdf documents) the same way?
Hi Johan,
If you need this to be possible then you will need to make the pdf documents as a part of your content structure.
It´s not possible to choose files from the media library with the related links data type.
/Dennis
how do I make the pdf documents as a part of your content structure?
Hi Johan,
You can use the related links if the files that you want to link to is external files. I am not sure that make the pdf documents a part of your content structure is the best solution.
But what you could do is create a pdf document type, on this document type use a media picker or a upload data type.
But if you just want to list files from a folder in the media library I would recommend you to use the media picker, on the page, and the select a folder from the media library, and loop through the folder and output the files.
Hope this helps,
/Dennis
Hi Dennis,
I tried this but it didn't work:
relateradokument is the alias of the media picker.
I want it to list the dokuments as links, but not sure how to do it.
Hi Johan,
This snippet of code below should do it for you. Remember to change @item.Name if you want the link text to be another property.
Hope this helps,
/Dennis
Hi Dennis,
This code isnt working for some reason..
Hi Johan,
Did your page have a folder selected, in the media picker.
You could try break the code down piece for piece to see where it fails. And please check that the property alias of the property is "relateradokument"
/Dennis
Hi Dennis,
The alias "relateradokument" is corrent,
The if statement works:
My page have a pdf file selected, not a folder.
Hi Johan,
Ah okay that´s where the problem is. With my code you will need to select a folder in the media library, and then the code will list all the items in this folder of the filetype file.
Please let me know if you only want to pick the a file and not a folder, and loop trough the files in the folder.
/Dennis
Hi Dennis,
Oh I see, I'm sorry that I wasn't clear from the start.
I only want to pick the file and not a folder.
How would the code look like?
Hi Johan,
Okay I am sure we can make that working too.
Try this code:
Hope this helps,
/Dennis
Thank you Dennis. It's working now if selected one file.
What if the user wants to pick multiple files (not inside a folder) through Multiple media picker?
How would the code look like then?
Hi Johan,
Then the code would look like this
Hope this works for you.
/Dennis
Thank you so much Dennis!
is working on a reply...