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

🔥 Feature: Add ctx.Bind for set default var map for template engine #1604

Closed
wants to merge 3 commits into from

Conversation

aztecrabbit
Copy link

Please provide enough information so that others can review your pull request:

#1536

Hi, i'm changing binding var type from interface{} to Map, is that ok?

@welcome
Copy link

welcome bot commented Oct 29, 2021

Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@liaohongxing
Copy link
Contributor

can render be changed to:

Render(*Ctx, io.Writer, string, Map, ...string) error

@ReneWerner87
Copy link
Member

can render be changed to:

Render(*Ctx, io.Writer, string, Map, ...string) error

why ?

@ReneWerner87
Copy link
Member

@liaohongxing why ?

@aztecrabbit
Copy link
Author

@ReneWerner87 Because we can easily implement for this feature (set default var map for tempate engine), and also no need to check binding arg type in every Render func in gofiber/template repo.

https://github.com/gofiber/template/blob/359ca25289df6bd214320ff864103d18051e5b01/jet/jet.go#L206-L252

@ReneWerner87
Copy link
Member

the same topic I had just answered here
#1622 (comment)
think it is unnecessary, because currently everything works and simply the bindings can be extended with the values that are needed

always having everything and introducing the context here is not really in line with clean code concepts and also makes writing unittests harder and using them outside the fiber context

@aztecrabbit
Copy link
Author

think it is unnecessary, because currently everything works and simply the bindings can be extended with the values that are needed

I'm using fiber not for api, pure using template engine. Sending session data to template engine in every route is too much work for me.

I'll close this pull request. But the feature like in this pull request will be added to fiber or not (maybe in fiber v3)? Because i think feature like this is very important for project that only using template engine.

@ReneWerner87
Copy link
Member

do not misunderstand, the "why" referred to the extension/adjustment of the render function with the context (first parameter)

the bind method is already useful and good, the only thing that prevents me from merging it is the adjustment of the type in the declaration, don't know if that causes a breaking change and then users have to make adjustments, even though it wouldn't really be necessary

@aztecrabbit
Copy link
Author

I missunderstand. I'm not seeing the source code of this repo for long time. I'm very sorry for this. Maybe i drinking too much coffee today, hahaha. Again, i'm so sorry @ReneWerner87

@ReneWerner87
Copy link
Member

is okay, does not matter :D , am always glad about every pull request

@ReneWerner87
Copy link
Member

@aztecrabbit can you check my last comments to the pull request, maybe we can make this backward compatible

@liaohongxing
Copy link
Contributor

liaohongxing commented Dec 28, 2021

I hope to change Render(io.Writer, string, interface(), ...string) error to Render(*Ctx, io.Writer, string, interface(), ...string) error in the next major version

Add a Ctx parameter, interface() can be changed to Map, it doesn’t matter

This is very helpful for me to write a custom template engine project, mainly to help me inject session, ctx.Local into the template

@ReneWerner87

@aztecrabbit
Copy link
Author

@ReneWerner87 The interface{} to Map think? I think not possible, because interface{} is too abstract for this. I think add this feature in fiber v3 is the best option right now

@ReneWerner87
Copy link
Member

fixed with #1754

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

Successfully merging this pull request may close these issues.

None yet

3 participants