Can't use "single" layout for success form sending page

I want to show a “Success” page after user successfully sent a form using the “single” page layout. So I have content file placed inside content/english/contact/success/_index.md But for some reason it still using page layout placed in myproject/themes/my_custom_theme/layouts/contact/list.html. Also I want “success” page to have example.com/contact/success url.

There’s my content files hierarchy:

myproject
├───content
│   └───english
│       │   _index.md
│       │
│       ├───about
│       │       _index.md
│       │
│       ├───contact
│       │   │   _index.md
│       │   │
│       │   └───success
│       │           _index.md
│       │
│       ├───faq
│       │       _index.md
│       │
│       ├───privacy-policy
│       │       _index.md
│       │
│       └───terms-conditions
│               _index.md

And layout filesof my custom theme:

myproject
└───themes
    └───my_custom_theme
        │   .gitignore
        │   config.toml
        │   theme.toml
        │
        ├───archetypes
        │       default.md
        │
        ├───assets
        │   ├───js
        │   │
        │   ├───plugins
        │   │   ├───bootstrap
        │   │   │       bootstrap.min.css
        │   │   │       bootstrap.min.js
        │   │   │
        │   │   └───jQuery
        │   │           jquery.slim.min.js
        │   │
        │   └───scss
        │       │   style.scss
        │       │
        │       └───templates
        │               _main.scss
        │               _navigation.scss
        │
        ├───i18n
        │       en.toml
        │
        └───layouts
            │   404.html
            │   index.html
            │
            ├───contact
            │       list.html
            │
            ├───faq
            │       list.html
            │
            ├───partials
            │       footer.html
            │       head.html
            │       header.html
            │       page-header.html
            │       preloader.html
            │       script.html
            │       style.html
            │
            ├───shortcodes
            │       base_url.html
            │       faq.html
            │       this_page_url.html
            │
            └───_default
                    baseof.html
                    list.html
                    single.html

How to use the single layout for page that must be available with example.com/contact/success url?

Changing success/_index.md to success/index.md (no underscore) should do the trick.

Details here:

1 Like

Thank you. It helps a lot. But is there a way to it only inside my theme? I’m performing redirect inside myproject/themes/my_custom_theme/layouts/contact/list.html and don’t want to get an error if user forgot to provide content/english/contact/success/index.md.

That’s a different topic.

At least for me it’s not clear from the description what you exactly want to achieve and when.

If the original question is solved. Mark a solution.
If not post more details.

For the new question, please create a new issue with elaborated content. Guess this will also need some more code to show. That seems to heavily depend on the templates code.

Sorry for misleading you. The main point is to define the contact/success/ page inside of my custom theme because I want to redirect to it from my theme logic. And it will be awkward if it will depend on presence of the /contact/success/index.md file. Moreover, it’s just a success page without any content except the localized message. So there’s no point in relying on this content file.

this will also need some more code to show

I don’t really understand what exactly template file code you want to see.

You can have a content file in your theme, too.
Unless the user defines same page in /content it will be taken from /themes/my-custom-theme/content

Dunno if this is considered hacky:-)

That one: regarding redirect

Perhaps my understanding of Hugo’s idea is incorrect. Please correct me if I’m wrong. The main point of Hugo is separation the site structure and its content, am I right? Content goes to content/, site structure goes to theme. Next Hugo uses theme to create pages and established relations between them.

But what if I want some behavior to reside in the theme only without being customizable within content/? In my case, I need a “success” page where my theme will redirect the user to. I thought if I rely on some page in my theme, that I must be sure that such page will exist whatever is going on in content/. This is why I started this topic - to figure out how to achieve this behavior in described way.

That one: regarding redirect

Maybe what I want to do is designed to be done differently in Hugo? Could you please explain it to me?

yes, it’s for separating, but

  • as far as I know -

the design concept is

a user always may override stuff delivered by the theme if he needs/wants.

  • If he does - his stuff will be used.
  • if not - the stuff from the theme is used

there’s nothing like theme private stuff - again as far as I know. if you download a theme locally you can adjust everything it delivers (full control).


my approach could be:

  • separate the success page in two parts
    • success layout template
      including a block or partial that is relevant for rendering the content
    • success content file
      providing the default content for the success page
  • document that for the users

which allows them to easily adjust the test of the success page without need to change any layouts


maybe one of the experts may want to jump in for that private stuff.

If you want to publish a page to a given path without creating a corresponding file in content, do either of the following:

1) Place an HTML file in the static directory. For example, static/foo/bar/index.html will be published to public/foo/bar/index.html.

2) Use resources.FromString within a template. The documentation includes an example.