-
Notifications
You must be signed in to change notification settings - Fork 204
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
Template directory config parameter (was: support for variables in file including tag) #7
Comments
This has been discussed in some of the other closed issues. I'm not sure if this was a design mistake. Should you really have the include tag behave like an expression:
It's really easy to change (well, the replacable context makes it a little bit more difficult) to make it behave like that and make it more flexible, but that would be a breaking change. Other way is to solve this with helper function or a view macro. Or just use template directly:
We could have by default a partial function (or you can create your own) that behaves like this:
Of course I do like breaking change here the most, but I'm not sure it is worth it. What you suggested was that instead of expression the include tag would behave as a template. Interesting approach indeed. Please look at some of the closed bugs where this is discussed (like this: #5 (comment)). Read also documentation about including templates and documentation about macros. And of course we could discuss this more. Would we like to introduce another tag, say Remember that lua-resty-template is really just a Lua code generator. Everything you can do in normal .lua files, you can do in templates as well. |
I think that this could be fixed with changes in these lines: local file = view:sub(e + 2, x - 1)
local a, b = file:find(',', 2, true)
if a then
c[#c+1] = '___[#___+1]=template.compile([=[' .. file:sub(1, a - 1) .. ']=])(' .. file:sub(b + 1) .. ')'
else
c[#c+1] = '___[#___+1]=template.compile([=[' .. file .. ']=])(context)'
end to c[#c+1] = '___[#___+1]=partial(view:sub(e + 2, x - 1))' Where this partial function is actually a template function in every template (so that it has access to default context). Partial function syntax is something like this: local function partial(file, ctx)
return template.compile(file)(ctx or context) -- where context is the default current context
end This way you could have code like this in template:
But this is a breaking change -> Any discussion, ideas, and contributions are welcomed! Regards |
Okay, I think I'm going to implement In Nginx/OpenResty context you can specify location with these: ... or are you looking something different? |
I already wrote |
В письме от Ср, 19 ноября 2014 14:34:38 пользователь Aapo Talvensaari написал:
Nice news! Thanks! ;) Best regards, |
Hi, The I also rewrote the whole parsing function. I tried several aproaches (like Still, I didn't yet release this as 1.4 as I like to test this rather big change for a little bit more. It looks like really solid now, but you never know. So, please go ahead, and checkout the latest sources from the master branch to get this new, yet to be released, version. Regards PS. I'm still thinking about implementing your second request about template dir. It's already supported in OpenResty context, I think, but I look forward adding support for other environments as well. |
### Added - Support for `template.new()` and `template.new(options)` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.root` and `template.location` properties ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()` and `template.new(options)` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.root` and `template.location` properties ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()` and `template.new(options)` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.root` and `template.location` properties ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()` and `template.new(options)` - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()` and `template.new(options)` - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()` and `template.new(options)` - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function` (#36) ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function` (#36) ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function` (#36) ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function` (#36) ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function` (#36) ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function (#36) ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function (#36) ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function (#36) ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function (#36) ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
### Added - Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function (#36) ### Changed - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (#32) ### Fixed - Wrong template returned when using multiple server blocks (#25) - Add a pure lua configure method (#23, #7)
You can now configure the template directory with |
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (bungle#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function (bungle#36) - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (bungle#32) - Wrong template returned when using multiple server blocks (bungle#25) - Add a pure lua configure method (bungle#23, #7)
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`) - Added `safe` implementation `require "resty.template.safe"` - Added `echo` helper function to template (bungle#28) - Added `template.load_file` and `template.load_string` functions - Added `template.compile_file` and `template.compile_string` functions - Added `template.parse_file` and `template.parse_string` functions - Added `template.render_file` and `template.render_string` functions - Added `template.precompile_file` and `template.precompile_string` functions - Added `template.process`, `template.process_file` and `template.process_string` functions - Added `template.root` and `template.location` properties - Added `template.visit` function (bungle#36) - When `plain` equals to `false` the file io issues are considered fatal, and assertions are thrown (bungle#32) - Wrong template returned when using multiple server blocks (bungle#25) - Add a pure lua configure method (bungle#23, #7)
Hi!
Can you add support for variables inside file including tag?
For example:
For now it only renders as text :(
The text was updated successfully, but these errors were encountered: