1

I created file upload section

            header.custom.portsPositionFile:
          type: file
          destination: 'user/themes/hlg/uploads'
          label: Select file with port position list
          accept:
            - .pdf

Now I want to display it inside my link

<a href="{{ header.custom.portsPositionFile }}">my link</a>

this return me empty array. How Can I display link to uploaded file?

MMPL1
  • 533
  • 7
  • 21

2 Answers2

1

A file field will allow for multiple files to be uploaded, therefore it will create two object: the first object is the list of the uploaded files, the nested object within is a group of property/value for the given file.

If you only have a single pdf, you therefore should be able to get the link by using the first filter. {{ page.header.custom.portsPositionFile|first.name }}

Paul Massendari
  • 417
  • 3
  • 6
  • It doesn't work. Return me nothing. Empty paragraph :/ – MMPL1 Jan 16 '18 at 12:51
  • same for {{ page.header.custom.portsPositionFile|first.name }} ? – Paul Massendari Jan 16 '18 at 12:51
  • oh, sorry it should be `{{ page.media[page.header.custom.portsPositionFile|first.name].url }}` Can you confirm it works? I will edit my answer – Paul Massendari Jan 16 '18 at 12:54
  • So, {{ page.header.custom.portsPositionFile|first.name }} return me proper file name. But your second code {{ page.media[page.header.custom.portsPositionFile|first.name].‌​url }} return me empty paragraph too – MMPL1 Jan 16 '18 at 12:56
  • But I think first.name construction should work with base_url – MMPL1 Jan 16 '18 at 12:57
  • yes, it should work by constructing it with base url. Can you just try `{{ page.media[header.custom.portsPositionFile|first.name].‌​url }}` – Paul Massendari Jan 16 '18 at 12:58
  • Same :/ empty paragraph/link – MMPL1 Jan 16 '18 at 13:01
  • ah, yes it's because you set destination to user/themes instead of a in the page itself. You therefore won't be able to use page.media on this page. Constructing the url with base_url will be easier in this case – Paul Massendari Jan 16 '18 at 13:08
  • ok, so where should I set destination? Create for example dir "uploads" in main dir with site? For now I have base_url solution – MMPL1 Jan 16 '18 at 13:10
  • You can use `destination: 'self@'` and it will store the pdf in the page itself, and you should be able to use page.media – Paul Massendari Jan 16 '18 at 13:27
0

From what I see in my frontmatter it outputs path not url so if you want this to work with the file being saved to any destination and not just @self then I'd try this:

{{ page.media[header.custom.portsPositionFile|first.path]​ }}

Trevor
  • 2,511
  • 1
  • 14
  • 25