<p>You can get the file’s contents using its <code>getContents()</code> method:</p>
<pre><code>{{ asset.getContents() }}`
</code></pre>
<p>That will HTML-encode the contents by default; if you need it to print unencoded, add the <code>|raw</code> filter. There are some big security concerns with doing that though, as the file could contain a <code>&lt;script&gt;</code> tag that facilitates an XSS attack.</p>

CC BY-SA 4.0
2021-06-06T13:50:28.653Z
2021-06-06T13:50:28.653Z
Brandon Kelly
<p>I'm looking to display/print the contents of an html or text file uploaded into assets. Not sure what parameter to access though.</p>
<p>Any help would be much appreciated!</p>

<assets>
How do I get the content from a text or html file in an assets directory to be displayed?
# How do I get the content from a text or html file in an assets directory to be displayed?

(Asked by: username_0 on 2021-06-06)

I'm looking to display/print the contents of an html or text file uploaded into assets. Not sure what parameter to access though.

Any help would be much appreciated!

**Tags:** assets

---

## 1 answers

### Answer by username_1 on 2021-06-06. Score: 1

You can get the file’s contents using its getContents() method:
{{ asset.getContents() }}`

That will HTML-encode the contents by default; if you need it to print unencoded, add the |raw filter. There are some big security concerns with doing that though, as the file could contain a


---

