Skip to content

How to call url by url name #217

Description

@alwismt

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🤔 QuestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions