Twig Grav CMS获取上传文件的url

Twig Grav CMS获取上传文件的url,twig,grav,Twig,Grav,我创建了文件上传部分 header.custom.portsPositionFile: type: file destination: 'user/themes/hlg/uploads' label: Select file with port position list accept: - .pdf 现在我想在我的链接中显示它 <a href="{{ head

我创建了文件上传部分

            header.custom.portsPositionFile:
          type: file
          destination: 'user/themes/hlg/uploads'
          label: Select file with port position list
          accept:
            - .pdf
现在我想在我的链接中显示它

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


这个返回给我空数组。如何显示上传文件的链接?

文件字段允许上传多个文件,因此它将创建两个对象:第一个对象是上传文件的列表,其中的嵌套对象是给定文件的一组属性/值

如果您只有一个pdf,那么您应该能够使用第一个过滤器获取链接。
{{page.header.custom.portsPositionFile | first.name}}
从我在frontmatter中看到的内容,它输出
路径
而不是
url
,因此,如果您希望将此操作用于将文件保存到任何目标,而不仅仅是
@self
,那么我将尝试以下操作:


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

除了指向的链接之外,您会选择指向哪里?您是在尝试创建一个文件上载部分,将其上载到管理区域还是前端(即为您站点的最终用户)?@martias我在管理区创建了文件上载部分。接下来我想在头版显示链接。链接sholud指向我在管理区上载的文件。@martias我想显示pdf文件的链接,如果它很重要但不起作用。不返回任何内容。空段落:{{page.header.custom.portsPositionFile | first.name}哦,对不起,应该是
{page.media[page.header.custom.portsPositionFile | first.name].url}
你能确认它工作吗?我会编辑我的答案,{{page.header.custom.portsPositionFile | first.name}返回正确的文件名。但是你的第二个代码是{{page.media[page.header.custom.portsPositionFile | first.name]。‌​url}}返回空段落,但我认为first.name构造应该与base_url一起使用