# Combining Data Ranges and Short Codes

**URL:** <https://discourse.gohugo.io/t/combining-data-ranges-and-short-codes/9864>\
**Category:** support\
**Created:** [January 5, 2018, 5:06pm UTC](https://discourse.gohugo.io/t/combining-data-ranges-and-short-codes/9864 "2018-01-05T17:06:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MusikPolice](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/musikpolice/32/4890_2.png) [@MusikPolice](https://discourse.gohugo.io/u/MusikPolice)\
**Post date:** [January 5, 2018, 5:06pm UTC](https://discourse.gohugo.io/t/combining-data-ranges-and-short-codes/9864/1 "2018-01-05T17:06:13Z")

</div>

I’d like to use the YouTube shortcode in conjunction with data templates to show a list of videos that is driven by the contents of a JSON file.

Ideally, in `site/content/index.md`, I’d have something like this:

```
# Some YouTube videos
{{ range $.Site.Data.youtube.videos }}
    {{< youtube .id >}}
{{ end }}

```

and in `site/data/youtube.yml`, I’d have something like this:

```
---
videos:
- id: abc123
- id: xyz456

```

so that each of the video ids that I list in my `.yml` file is rendered as an embedded YouTube video on my homepage.

The problem here is that I can’t seem to use hugo functions like `range` in `.md` files. When I try this, the first code snippet just gets rendered as text, rather than being replaced with YouTube videos.

Fair enough, let’s extract the code into a partial that lives in `site/layouts/partials/youtube-list.html`:

```
{{ range $.Site.Data.youtube.videos }}
    {{< youtube .id >}}
{{ end }} 

```

Then we’ll modify `site/content/index.md` to reference the partial:

```
# Some YouTube Videos
{{ partial "youtube-list.html" . }}

```

Now, when I try to run the server, Hugo tells me that I can’t use the `<` character in a partial:

```
ERROR 2018/01/05 11:30:33 partials/youtube-list.html : template: partials/youtube-list.html:2: unexpected "<" in command

```

Great. I suppose I could create a custom shortcode instead, but they appear to have the same limitation - a shortcode cannot reference another shortcode:

```
ERROR 2018/01/05 11:32:39 shortcodes/youtube-list.html : template: shortcodes/youtube-list.html:3: unexpected "<" in command

```

I guess I could find the source for the YouTube shortcode in Hugo’s GitHub repository and “borrow” it wholesale for use in my new shortcode, but that seems like unnecessary duplication of code.

**tl;dr:** Is there any way to combine data templates and shortcodes in Hugo so that the same shortcode is used to render each element in a list that is read from a data template?

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [January 5, 2018, 5:33pm UTC](https://discourse.gohugo.io/t/combining-data-ranges-and-short-codes/9864/2 "2018-01-05T17:33:14Z")

</div>

You can only use shortcodes in content files. You can’t use shortcodes in templates, and you can’t use template logic in content.

You should probably create your own shortcode. You can see the [embedded youtube shortcode here](https://github.com/gohugoio/hugo/blob/23f69efb3914946b39ce673fcc0f2e3a9ed9d878/tpl/tplimpl/template_embedded.go#L40-L48).
