Linking to another page

Hello,

I’m going nuts trying to get this to work, from my homepage I have a link called “Features” which links to “/features/”, now I want to have a special template running for just that “subpage” but the closest I can get is having that page displayed the same as my “Blog” page, which uses single.html and list.html from the _default folder, does anyone have a solution for me, can’t really find what I need in the docs.

Thanks!

Lots of ways to do it, but one way is to create a layout specifically for that page, and assign the features page the layout in front matter. Knowing the lookup order is the important bit.

1 Like

Thanks, I’ve got it working now, although I think there’s a strange behavior, in my content/features/ folder I have a file called _index.md which basically only stores a title for that specific “subpage”, but for my layout stored in layouts/features to work properly it needs to be called list.html which is strange as there aren’t any more files in my content folder and as such I would think that the layout file should be called single.html instead, am I missing something here?
Thanks!

In case you want to use code rather than emphasis for file names:

As for yer deal, I’d come at it from a different angle. You are trying to fit your special page into the site, but instead figure out what kind of page it is, and then modify the correct template.

For instance, is features a directory or a single page? _index.html is for adding content to the various list views (sections, taxonomies, those kinds of things). It sounds like you want a single page that renders differently than the other single pages on your site.

If I were doing this, I’d probably put special one-off pages in their own section, and using front matter I’d set everything.

content/pages/features.md:

title: "Features"
layout: "special"
slug: "features"

Then I’d create a template based on the single page lookup order, which given my example would be at /layouts/pages/special.html.

That should do it for ya!

If this seems more difficult than it needs to be, it is because we have an open convention (lookup order) to allow for maximum flexibility. You can accomplish your goal differently, and it is just as valid. But really focus on understanding the lookup order and you’ll figure out what works for your site. :slight_smile:

Hi,

I tried doing exactly as you suggested, this is my structure now:

content/pages/features.md:

---
title: "Features"
layout: "special"
slug: "features"
---

layouts/pages/special.html:

<!DOCTYPE html>
<html lang="{{ with .Site.LanguageCode }}{{ . }}{{ else }}en-US{{ end }}">

  {{ partial "head.html" . }}

  <body id="page-top" class="index">
    {{ partial "nav.html" . }}
    
    {{ partial "hero.html" . }}

    {{ partial "e-commerce.html" . }}

    {{ partial "social_feed.html" . }}

    {{ partial "marketplace.html" . }}

    {{ partial "steps.html" . }}

    {{ if .Site.Params.footer.enable }}
      {{ partial "footer.html" . }}
    {{ end }}

    {{ partial "js.html" . }}
  </body>
</html>

Navigating to /features/ now gives me a 404 instead :confused:
Navigating to /pages/features/ does give me what I want though, although I do not want the /pages part.

Oh yeah, sorry, you need to set permalinks. To immediately fix your features page, override the URL in front matter:

---
title: "Features"
layout: "special"
url: "/features/"
---

However! You can also change all the permalinks for the section by adding the following to your config.html:

permalinks:
  pages: /:slug/

Then all the content you put in the pages section will take their slug or title and generate the URL off the baseURL. If I add an about page at /content/pages/about.md that looks like:

title: "About"

It will create the page at example.org/about. I use :slug in the permalink so I can override. For instance, the following also generates the same about URL as the previous example:

title: "About all the awesome things I put online"
slug: "about"

Note: your site will look for permalinks in the config, and then override on a per content basis. So you can combine the two methods I’ve added here, but if you do without fully understanding it you will run into trouble. So for now, pick one or the other.

Finally, the reason to put pages in a section like that is if you have a lot of pages that hang off the root domain, you can keep them in their own directory, rather than in your content directory. It is tidier. :slight_smile:

Ah, great, thanks, will try it out first thing tomorrow at work :slight_smile: