# How to use partials for only certain pages

**URL:** <https://discourse.gohugo.io/t/how-to-use-partials-for-only-certain-pages/14903>\
**Category:** support\
**Created:** [October 25, 2018, 2:45pm UTC](https://discourse.gohugo.io/t/how-to-use-partials-for-only-certain-pages/14903 "2018-10-25T14:45:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@prophet](https://discourse.gohugo.io/u/prophet)\
**Post date:** [October 25, 2018, 2:45pm UTC](https://discourse.gohugo.io/t/how-to-use-partials-for-only-certain-pages/14903/1 "2018-10-25T14:45:48Z")

</div>

I’m starting with Hugo, and the block templates are a nice feature to have, altought I have some questions of something that I might be not understaing well.

I create a .html inside Partials folder that I want to use throughout the whole site. So let’s say I have:

{{ partial “my-new-partial” . }}

I cannot use this inside Content folder? So how can I use this template blocks in the whole site? Thank you!

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [October 25, 2018, 3:09pm UTC](https://discourse.gohugo.io/t/how-to-use-partials-for-only-certain-pages/14903/2 "2018-10-25T15:09:50Z")

</div>

Partials are commonly referenced from your `layouts/_default/baseof.html`. For example:

```auto
<!DOCTYPE html>
<html>
  {{- partial "head.html" . -}}
  <body>
    {{- partial "header.html" . -}}
    {{- block "main" . }}{{- end }}
    {{- partial "footer.html" . -}}
  </body>
</html>

```

Then, for example, in your `layouts/index.html`, you would define what goes into the main block:

```auto
{{- define "main" -}}
<!-- Some code here -->
{{- end -}}

```

Does that help?

---

<div class="post-metadata">

**Author:** ![prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@prophet](https://discourse.gohugo.io/u/prophet)\
**Post date:** [October 25, 2018, 3:13pm UTC](https://discourse.gohugo.io/t/how-to-use-partials-for-only-certain-pages/14903/3 "2018-10-25T15:13:42Z")

</div>

Yes, that’s what I’ve been doing. But imagine I have a partial that I don’t want in X, Y and Z pages. If I already have on the _baseof.html_ that partial, how can I remove in the X, Y and Z pages?

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [October 25, 2018, 3:16pm UTC](https://discourse.gohugo.io/t/how-to-use-partials-for-only-certain-pages/14903/4 "2018-10-25T15:16:47Z")

</div>

I see what you’re asking now. Well, there are a few way to do this. For example, say you only wanted to include a partial on pages of type post. In your `baseof.html` you would do:

```auto
{{ if eq .Type "post" }}
  {{- partial "some-partial.html" . -}}
{{ end }}

```

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [October 25, 2018, 3:21pm UTC](https://discourse.gohugo.io/t/how-to-use-partials-for-only-certain-pages/14903/5 "2018-10-25T15:21:56Z")

</div>

For valid `.Type` values, see

> **[Content Types](https://gohugo.io/content-management/types/)**
>
> Hugo supports sites with multiple content types and assumes your site will be organized into sections, where each section represents the corresponding type.

You could also do a check on `.Kind`

> **[Section Page Templates](https://gohugo.io/templates/section-templates/#page-kinds)**
>
> Templates used for section pages are \*\*lists\*\* and therefore have all the variables and methods available to list pages.

---

<div class="post-metadata">

**Author:** ![prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@prophet](https://discourse.gohugo.io/u/prophet)\
**Post date:** [October 25, 2018, 3:29pm UTC](https://discourse.gohugo.io/t/how-to-use-partials-for-only-certain-pages/14903/6 "2018-10-25T15:29:34Z")

</div>

That works!! Thank you!

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [October 25, 2018, 5:44pm UTC](https://discourse.gohugo.io/t/how-to-use-partials-for-only-certain-pages/14903/7 "2018-10-25T17:44:46Z")

</div>

@prophet I changed your thread title from

> Best way to add functions inside pages

To

> How to use partials for only certain pages

For easier forum searching later on
