How to get document name in module html

I have a custom module. One of the fields is of type File, and the “File type” is Document. The field is called resources and is repeating.
If I write the following, I get a list of resources, but only the URL is displayed:

<ul>
 {% for resource in module.resources %}
 <li><a href="{{ resource }}">{{ resource }}</a></li>
 {% endfor %}
</ul>

But I’d like to make use of the document name as well as its URL. Ideally something like:

<ul>
 {% for resource in module.resources %}
 <li><a href="{{ resource.url }}">{{ resource.name }}</a></li>
 {% endfor %}
</ul>

But url and name (or title) aren’t recognized properties of resource.

Is this possible?

Hi @Pixton ,

You can use the |pprint filter to check the contents of a variable. So use {{resource|pprint}} to check what is available. This won’t solve your current issue tho, just a tip.

If I am not mistaken, the name of the file should be available in the URL, so you could use a filter to strip out part of the URL and it should leave you with the name of the file, correct?
You could try using the regex_replace or the replace filter.

If you need help with that, let me know!

Thank you, @Teun! That’s super helpful.