Answers.Body: <p>What do you mean by 'display the asset'? Showing a thumbnail is not an option, because no thumbs are made for PDF files. If you'd want to show the filename, for example, use the <a href="http://buildwithcraft.com/docs/templating/assetfilemodel#filename" rel="nofollow">filename</a> property of the asset.</p>
  
  <p>If the page contains multiple entries, you'd have to loop through the entries first. Then, for each entry, check if it has an asset in the desired field (by using <code>| length</code>, after which you can display the asset.</p>
  
  <pre><code>{% for entry in craft.entries.section('bla').relatedTo('bla') %}
      {% if entry.dataCard | length %}
          {% set asset = entry.dataCard.first() %}
          &lt;a href="{{ asset.url }}"&gt;{{ asset.filename }}&lt;/a&gt;
      {% endif %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-07T12:21:37.023Z
Answers.Text: FYI - you _can_ use [PThumb](https://github.com/carnesmedia/pthumb) or [pdfthumbnails](https://github.com/johndryan/pdfthumbnails) if your server supports ImageMagick. This allows you to create thumbnails for PDFs.
Answers.UserDisplayName: crawf
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T17:52:50.367Z
Answers.LastActivityDate: 2015-05-06T17:52:50.367Z
Answers.UserDisplayName: Paul
Body: <p>I have an asset field (dataCard) which I use to upload a single PDF file tied to an entry. I'm trying, unsuccessfully, to display the asset tied to the entry on a page listing multiple entries. How would I do this? This is what I have so far:</p>
  
  <pre><code>{% set asset = entry.dataCard.first() %}
  
  {% if asset %}
      &lt;a href="{{ asset.url }}"&gt;{{category.title}}&lt;/a&gt;
  {% endif %}
  </code></pre>
  
Tags: <templating><entries><assets>
Title: How do you display a file asset (PDF) in the template?
ThreadText: # How do you display a file asset (PDF) in the template?
  
  (Asked by: username_0 on 2015-05-06)
  
  I have an asset field (dataCard) which I use to upload a single PDF file tied to an entry. I'm trying, unsuccessfully, to display the asset tied to the entry on a page listing multiple entries. How would I do this? This is what I have so far:
  
  ```
  {% set asset = entry.dataCard.first() %}
  
  {% if asset %}
      <a href="{{ asset.url }}">{{category.title}}</a>
  {% endif %}
  
  ```
  
  **Tags:** templating, entries, assets
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-05-06. Score: 2 | Accepted answer
  
  What do you mean by 'display the asset'? Showing a thumbnail is not an option, because no thumbs are made for PDF files. If you'd want to show the filename, for example, use the [filename](http://buildwithcraft.com/docs/templating/assetfilemodel#filename) property of the asset.
  
  If the page contains multiple entries, you'd have to loop through the entries first. Then, for each entry, check if it has an asset in the desired field (by using `| length`, after which you can display the asset.
  
  ```
  {% for entry in craft.entries.section('bla').relatedTo('bla') %}
      {% if entry.dataCard | length %}
          {% set asset = entry.dataCard.first() %}
          <a href="{{ asset.url }}">{{ asset.filename }}</a>
      {% endif %}
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_2**: FYI - you _can_ use [PThumb](https://github.com/carnesmedia/pthumb) or [pdfthumbnails](https://github.com/johndryan/pdfthumbnails) if your server supports ImageMagick. This allows you to create thumbnails for PDFs.  
  
  ---
  
  