CMS Development

Pixton
Participant

How to get document name in module html

SOLVE

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?

0 Upvotes
1 Accepted solution
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to get document name in module html

SOLVE

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!



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


View solution in original post

2 Replies 2
Pixton
Participant

How to get document name in module html

SOLVE

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

Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to get document name in module html

SOLVE

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!



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.