# Static page that uses partials

**URL:** <https://discourse.gohugo.io/t/static-page-that-uses-partials/52479>\
**Category:** support\
**Created:** [November 20, 2024, 11:33am UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479 "2024-11-20T11:33:52Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paolo](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Paolo](https://discourse.gohugo.io/u/Paolo)\
**Post date:** [November 20, 2024, 11:33am UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/1 "2024-11-20T11:33:52Z")

</div>

I have a single HTML page in `static`. I’d like this page to use the same CSS/SCSS as the other pages on my website.

Is there a way I can use partials in this static page? If not, what is the best practice for dealing with this? Do I have to resort to injecting lines with something like sed?

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [November 20, 2024, 2:29pm UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/2 "2024-11-20T14:29:25Z")

</div>

> [@Paolo](#):
>
> Is there a way I can use partials in this static page?

No.

> [@Paolo](#):
>
> If not, what is the best practice for dealing with this?

Hard to say without knowing the details. Is there a reason you can’t treat this file as content with a unique template??

---

<div class="post-metadata">

**Author:** ![Paolo](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Paolo](https://discourse.gohugo.io/u/Paolo)\
**Post date:** [November 21, 2024, 9:55am UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/3 "2024-11-21T09:55:07Z")

</div>

> [@jmooring](#):
>
> Is there a reason you can’t treat this file as content with a unique template??

How would I go about doing that? Since the .md page would have no content.

Let’s say I want the page to be under _/foo/bar/api_  
then I would create

> content/foo/bar/api.md

with the following content:

```auto

---
Title: API
layout: api
---

```

correct?

But I can’t ever get the layout to work.  
I tried creating

> layouts/api/single.html  
> layouts/foo/bar/api/single.html

but neither work

---

<div class="post-metadata">

**Author:** ![specimen](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@specimen](https://discourse.gohugo.io/u/specimen)\
**Post date:** [November 21, 2024, 11:35am UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/4 "2024-11-21T11:35:58Z")

</div>

> [@Paolo](#):
>
> `layout: api`

You should create a layout called `api.html` in the `_default` layouts folder.

---

<div class="post-metadata">

**Author:** ![Paolo](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Paolo](https://discourse.gohugo.io/u/Paolo)\
**Post date:** [November 21, 2024, 11:51am UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/5 "2024-11-21T11:51:19Z")

</div>

> [@specimen](#):
>
> You should create a layout called `api.html` in the `_default` layouts folder.

Thank you. I think it’s picking up the HTML file now but the page I’m seeing is not what I would expect, the HTML page isn’t being shown correctly. Its different compared to what I see if I run an http-server and load the HTML page at [http://127.0.0.1:8080/layouts/\_default/api.html](http://127.0.0.1:8080/layouts/_default/api.html)

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [November 21, 2024, 4:12pm UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/6 "2024-11-21T16:12:59Z")

</div>

> [@Paolo](#):
>
> [http://127.0.0.1:8080/layouts/\_default/api.html](http://127.0.0.1:8080/layouts/_default/api.html)

The above is either a typographical error, or a conceptual disconnect.

The page you created is served at:  
`http://localhost:1313/foo/bar/api`

> [@Paolo](#):
>
> Its different compared to what I see

Are you trying to open the file directly from the file system instead of serving it? If so, don’t do that.

Working example:

```plaintext
git clone --single-branch -b hugo-forum-topic-52479 https://github.com/jmooring/hugo-testing hugo-forum-topic-52479
cd hugo-forum-topic-52479
hugo server

```

---

<div class="post-metadata">

**Author:** ![Paolo](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Paolo](https://discourse.gohugo.io/u/Paolo)\
**Post date:** [November 21, 2024, 4:49pm UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/7 "2024-11-21T16:49:04Z")

</div>

> [@jmooring](#):
>
> The above is either a typographical error, or a conceptual disconnect.

There’s no error. Like I said I’m loading that page after starting an http-server (nodejs server).

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [November 21, 2024, 4:50pm UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/8 "2024-11-21T16:50:26Z")

</div>

> [@Paolo](#):
>
> [http://127.0.0.1:8080/layouts/\_default/api.html](http://127.0.0.1:8080/layouts/_default/api.html)

Ok, so, the above isn’t a thing.

I suggest you compare what you have done with the working example that I provided.

---

<div class="post-metadata">

**Author:** ![Paolo](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Paolo](https://discourse.gohugo.io/u/Paolo)\
**Post date:** [November 21, 2024, 4:50pm UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/9 "2024-11-21T16:50:27Z")

</div>

> [@jmooring](#):
>
> Are you trying to open the file directly from the file system instead of serving it? If so, don’t do that.

I’m running hugo serve. The page I see is not the same page I see on the http-server.

---

<div class="post-metadata">

**Author:** ![Paolo](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Paolo](https://discourse.gohugo.io/u/Paolo)\
**Post date:** [November 21, 2024, 4:50pm UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/10 "2024-11-21T16:50:53Z")

</div>

> [@jmooring](#):
>
> Ok, so, the above isn’t a thing

So there’s no alternative to static pages?

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [November 21, 2024, 4:51pm UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/11 "2024-11-21T16:51:30Z")

</div>

> [@jmooring](#):
>
> I suggest you compare what you have done with the working example that I provided.

Please see my previous comment.

---

<div class="post-metadata">

**Author:** ![Paolo](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Paolo](https://discourse.gohugo.io/u/Paolo)\
**Post date:** [November 22, 2024, 10:55am UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/12 "2024-11-22T10:55:44Z")

</div>

I’ve got it working for a brand new hugo project with a recent hugo version.  
In what version did hugo introduce layout targeting?

---

<div class="post-metadata">

**Author:** ![Paolo](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Paolo](https://discourse.gohugo.io/u/Paolo)\
**Post date:** [November 22, 2024, 12:10pm UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/13 "2024-11-22T12:10:29Z")

</div>

Found the issue. There was a single.html affecting how the page was being formatted.

---

<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:** [November 24, 2024, 12:11pm UTC](https://discourse.gohugo.io/t/static-page-that-uses-partials/52479/14 "2024-11-24T12:11:00Z")

</div>

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