2

I'm trying to create a layout for my website where I use partials for my header and footer.


<!DOCTYPE html>
<html lang="en">
    <head>
        <title>{{title}}</title>
        <script src="https://unpkg.com/[email protected]" crossorigin="anonymous"></script>
        <link href='/static/css/global.css' rel='stylesheet'>   
        <link href='https://fonts.googleapis.com/css?family=Rubik' rel='stylesheet'>
    </head>
    <body>
        {{> views/partials/header }}
        {{{embed}}}
        {{> views/partials/footer }}
    </body>
</html>

I followed the example as shown here: https://docs.gofiber.io/template/mustache/

The embedding works fine, but the partials won't work.

My file structure is like this:

views
├── layout.mu
└── partials
    ├── header.mu
    └── footer.mu

Here is how I setup the app and route:

engine := mustache.New("./views", ".mu")
app := fiber.New(fiber.Config{Views: engine})

app.Get("/", func(c *fiber.Ctx) error {
        return c.Render("index", fiber.Map{
            "title": "index",
        }, "layout")
    })

And finally here is my header:

<nav class="navigation">
    <a href="/"><img alt="" class="logo" src="/static/images/logo.png"/></a>    
    <ul class="items">
        <li>
            <a class="links" href="/product">Produkt</a>
        </li>
        <li>
            <a class="links" href="/blog">Blogg</a>
        </li>
        <li>
            <a class="links" href="/about">Om Oss</a>
        </li>
        <li>
            <a class="links contact" href="/contact">Kontakta Oss</a>
        </li>
    </ul>
</nav>

1 Answer 1

0

I guess you probably solved it now. But for future users I post the solution here.

The file extension must be .mustache otherwise the template engine will not be able to render the file from partials when included.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.