Git Product home page Git Product logo

Comments (4)

zachmann avatar zachmann commented on September 3, 2024

I submitted PR #104 to fix this issue. The PR introduces a new function NewFileSystemPartials which takes a Filesystem specially for partials (of course a user instead can also use the same Filesystem already used for the other template files). If the partialFileSystem is set the above call to mustache.ParseString is replaced with a call to mustache.ParseStringPartials that uses the embedded Filesystem for the partials.

Feel free to adapt the PR.

from template.

ReneWerner87 avatar ReneWerner87 commented on September 3, 2024

hi i tried it myself, with partials in the embedded filesystem and it seems to work, without any adjustments

package main

import (
    "embed"
    "log"
    "net/http"

    "github.com/gofiber/fiber/v2"
    "github.com/gofiber/template/mustache"
)

//go:embed views/*
var viewsfs embed.FS

func main() {

    engine := mustache.NewFileSystem(
        http.FS(viewsfs),
        ".mustache",
    )

    // Pass the engine to the Views
    app := fiber.New(fiber.Config{
        Views: engine,
    })


    app.Get("/", func(c *fiber.Ctx) error {
        // Render index
        return c.Render("views/index", fiber.Map{
             "Title": "Hello, World!",
        })
    })

    log.Fatal(app.Listen(":3000"))
}

views folder from here:
https://github.com/gofiber/template/tree/master/mustache/views

Output:
image

from template.

zachmann avatar zachmann commented on September 3, 2024

It only works if / because the files are (also) available on the real filesystem on the correct (expected) paths. If you run the binary from a different location, the paths are not as expected anymore and it will not find the partials, which results in only rendering the Hello, World!.

I'll update the PR with the requested changes.

from template.

ReneWerner87 avatar ReneWerner87 commented on September 3, 2024

ok, thx

from template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.