# Render content with two different HTML templates

**URL:** <https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799>\
**Category:** support\
**Created:** [May 10, 2021, 4:38am UTC](https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799 "2021-05-10T04:38:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgarr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jgarr/32/14309_2.png) [@jgarr](https://discourse.gohugo.io/u/jgarr)\
**Post date:** [May 10, 2021, 4:38am UTC](https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799/1 "2021-05-10T04:38:38Z")

</div>

I would like to take my content in ./content/posts and render it twice with two different templates. I looked at custom outputs but that didn’t seem like what I wanted because both of my templates render html.

I looked into content view templates and this seems closer to what I want but I can’t figure out if it can be used to render pages twice.

I made a custom template for my content called “embed” and what I currently do is move all the content into ./content/embed and then run `hugo` to render the content into /public. I copy the rendered pages into ./static and then copy my content to ./content/posts and re-render the site.

You can see the rendered output live at [posts](https://123dev.email/posts/18/) and [embed](https://123dev.email/embed/18/)

Does anyone know if this is natively supported with hugo or should I stick with my current workflow of rendering the content twice?

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [May 10, 2021, 6:18am UTC](https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799/2 "2021-05-10T06:18:48Z")

</div>

As far as I know, one can have multiple Output Formats for the same file format.

Simply define the second HTML output as `EMBED` or something. Then make sure to disable indexing from search engines (if you are concerned about getting duplicate content penalties).

I am not aware of another way that you could achieve what you want.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [May 10, 2021, 7:00am UTC](https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799/3 "2021-05-10T07:00:57Z")

</div>

> [@alexandros](#):
>
> As far as I know, one can have multiple Output Formats for the same file format.

You can.

---

<div class="post-metadata">

**Author:** ![jgarr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jgarr/32/14309_2.png) [@jgarr](https://discourse.gohugo.io/u/jgarr)\
**Post date:** [May 10, 2021, 4:23pm UTC](https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799/4 "2021-05-10T16:23:49Z")

</div>

Thanks for pointing me in that direction. I re-read the docs and started creating a custom output format. I added this to my config.toml

```auto
[outputs]
  page = ["HTML", "EMBED"]

[outputFormats]
  [outputFormats.embed]
    name = "embed"
    path = "embed"
    isHTML = true

```

And then added my templates to `layouts/posts/single-baseof.embed.html` and `layouts/posts/single.embed.html`

I obviously did something wrong because I see this warning for each page

```auto
WARN 2021/05/10 09:21:22 found no layout file for "embed" for kind "page": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

```

But also my regular home page and standard HTML templates are all broken. I’ll keep digging into the docs to see what I’m missing or did wrong.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [May 10, 2021, 8:39pm UTC](https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799/5 "2021-05-10T20:39:46Z")

</div>

> [@jgarr](#):
>
> ```auto
> [outputFormats]
> [outputFormats.embed]
> name = "embed"
> path = "embed"
> isHTML = true
> 
> ```

I’m surprised that we don’t throw an error about this, but the output format defintion needs a media type:

```auto
mediaType = "text/html"

```

With the above, Hugo should be able to fall back to `single.html` etc., but if you want a template for that output format, you can do `single.embed.html` etc.

You may ask what the `isHTML` flag is for, but that is a longer story.

---

<div class="post-metadata">

**Author:** ![jgarr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jgarr/32/14309_2.png) [@jgarr](https://discourse.gohugo.io/u/jgarr)\
**Post date:** [May 10, 2021, 11:25pm UTC](https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799/6 "2021-05-10T23:25:25Z")

</div>

Thank you so much! I think that solved the problem for me.

---

<div class="post-metadata">

**Author:** ![jgarr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jgarr/32/14309_2.png) [@jgarr](https://discourse.gohugo.io/u/jgarr)\
**Post date:** [May 11, 2021, 12:16am UTC](https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799/7 "2021-05-11T00:16:27Z")

</div>

One last question I’m not sure if it’s possible. I see the path is added to the content type (eg `embed/posts`) is there any way to make the path replace `posts` in the URL? It’s not a big deal if it can’t but it makes some of my regex easier to match if the word is one or another

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [May 11, 2021, 4:46am UTC](https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799/8 "2021-05-11T04:46:16Z")

</div>

It is not currently possible to configure permalinks per Custom Output Format.

The [Permalinks Configuration](https://gohugo.io/content-management/urls/#permalinks-configuration-example) works for sections across all Outputs.

---

<div class="post-metadata">

**Author:** ![jgarr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jgarr/32/14309_2.png) [@jgarr](https://discourse.gohugo.io/u/jgarr)\
**Post date:** [May 11, 2021, 6:00am UTC](https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799/9 "2021-05-11T06:00:24Z")

</div>

Thanks for clarifying. 😀

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [May 13, 2021, 6:00am UTC](https://discourse.gohugo.io/t/render-content-with-two-different-html-templates/32799/10 "2021-05-13T06:00:36Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
