Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤗 [Question]: How can i divide my layout, component and views folders #282

Closed
3 tasks done
Necoo33 opened this issue Aug 21, 2023 · 4 comments
Closed
3 tasks done
Labels
🤔 Question Further information is requested

Comments

@Necoo33
Copy link

Necoo33 commented Aug 21, 2023

Question Description

Hello, i want to know how to structure my code with the way that components, layouts and pages/views are individual folders in same directory.

It would be great if you do necessary changes on the following code:

package main

import (
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/template/html/v2"
)

func main() {
	htmlFiles := html.New("./pages", ".html")
	htmlFiles.Reload(true)

	server := fiber.New(fiber.Config{
		Views: htmlFiles,
	})

	server.Get("/", func(context *fiber.Ctx) error {
		return context.Render("home", fiber.Map{
			"Data": "Hello",
		})
	})

	server.Listen(":2000")
}

Code Snippet (optional)

package main

import "github.com/gofiber/template/%package%"

func main() {
  // Steps to reproduce
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.
@Necoo33 Necoo33 added the 🤔 Question Further information is requested label Aug 21, 2023
@ReneWerner87
Copy link
Member

you can do it like in our example projects
https://github.com/gofiber/recipes/tree/master/template

@Necoo33
Copy link
Author

Necoo33 commented Aug 21, 2023

you can do it like in our example projects
https://github.com/gofiber/recipes/tree/master/template

I want to make all the three folders in same tree level on the root directory like this:

components
pages
layouts
mainpoint(main package exist int here)
go.work
go.sum

@ReneWerner87
Copy link
Member

You can use the root folder as view folder
since we have the extension in the engine, all files that do not match the extension will be skipped

@Necoo33
Copy link
Author

Necoo33 commented Aug 21, 2023

You can use the root folder as view folder since we have the extension in the engine, all files that do not match the extension will be skipped

Thanks, it worked. I think you should consider allowing to put layout and view folders in the root directory without setting root folder of engine as view folder, for the sake of avoid to give access to all folders in the root directory when we want to structure our layouts and pages in the same tree level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants