2
votes

I'm fairly new to Orchard and I'm wondering about the "best" way of building a basic list of documents with a download link?

Say the scenario is this, I want to make a list of newsletters, the news letter are in PDF format and the users should be able to download then straight from the list view. An admin, should easily be able to add a new newsletter and it should turn up in the list.

My current train of thought is to, all through the dashboard,

  1. create a content type "Newsletter" with a title field and a Media picker field, using the media picker field to upload the PDF file.
  2. Then create a query, with the filter on Content type "Newsletter"
  3. Create a projection pointing to the query

However, this only gives me a list of content items, showing their title as links back to the actual content item.

I've tried adding a layout to the query and set it to display properties instead of content. By doing that I can get a list where I can control the "output" a bit more. And I've gotten it to list the title and by doing a Rewrite and putting in the MediaPicker.Url, it also displays the URL in the list. This is all good but here I get stuck..

As the MediaPicker.URL outputs the url in the format like ~/media/default/xyz/filename.pdf, I cant just put it into a a href, it doesn't give a correct download link to the file.

Soo, question is, am I thinking and doing this totally the wrong way or am I missing something obvious? All ideas and suggestions and more then welcome.

1
Did you try any of those modules? gallery.orchardproject.net/List/…Bertrand Le Roy
Just a note on media picker: I think the bug you mention is fixed on the 1.x branch, and you can work around it in previous versions with a template override. The tilda in front just needs to be removed.Bertrand Le Roy
@Bertrand Le Roy, Thanks for the suggestions and yep, I tried the modules from the gallery, unfortunately, they either, don't work with 1.6, are unstable or don't address what I'm trying to do :/. I tried with the 1.x branch but it seems to have the same issue, so I'm now looking at overriding the template.Ola Karlsson
If it's still not fixed in 1.x, please file a bug. I'm copying a template override that I built for a site in an answer below.Bertrand Le Roy
Thanks @Bertrand Le Roy, see issue submitted here orchard.codeplex.com/workitem/19442Ola Karlsson

1 Answers

0
votes

Use or adapt the following template override in your theme:

@{
    var url = Model.ContentField.Url;
}
@if(Model.ContentField.Url != null) {
    if (url.StartsWith("~/")) {
        url = Href(url);
    }
    <div class="media-picker-field attachment-pdf">
        <a href="@url" class="pdf-download" title="@T("Download the PDF")"><span>download</span></a>
    </div>
}

Modify the text as needed. This template was a Fields.MediaPicker-PDF.cshtml that was used for a media picker field named PDF.