How to call url by url name
Open
Nobody has claimed this yet.
🤔 Question
- Dominant language
- Go
- Stars
- 314
- Forks
- 61
- Avg merge
- 4h 35m
- Merged PRs (30d)
- 12
Description
I have below route my project with name now i wanna call them inside templates
func ProductRoutes(a *fiber.App) {
pc := controllers.ProductController{}
// admin route
route := a.Group("/admin/product")
// add auth middleware to dashboard group
route.Use(middleware.AuthProtected)
route.Get("/", pc.Index).Name("product_index") // get all products
route.Get("/add", pc.Add).Name("product_add") // add new product form
route.Post("/", pc.Insert).Name("product_insert") // add new product to database
route.Get("/:id", pc.Show).Name("product_show") // get a product with an ID
route.Put("/:id", pc.Update).Name("product_update") // update a product with an ID
route.Delete("/:id", pc.Destroy).Name("product_delete") // delete a product
}
Below my controller
func (pc *ProductController) Index(c *fiber.Ctx) error {
session.Get(c, "user_id")
user := fiber.Map{
"name": session.Get(c, "name"),
"email": session.Get(c, "email"),
}
search := c.Query("search")
return c.Render("product/index", fiber.Map{
"title": "Selectify Admin",
"admin": user,
"active": "products",
"url": c.OriginalURL(),
"search": search,
})
}
I wanna call product_index inside template
<a href='{{ routePath "product_index" }}'>Products</a>
I tried few ways and search over google didn't found any answer, is there any way to do that?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ProductRoutes and ProductController.Index, then trace how the template rendered by c.Render receives functions. Check whether the requested routePath helper is supported for named routes; done means the template can reference product_index, or the limitation and supported usage are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend, web-dev
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100