Closed challmand closed 9 months ago
Djula uses access
library for accessing objects.
But access
does not seem to work for structs?
I've tested with (access:access (make-person :name "lala") 'name)
.
And I get NIL
.
That's strange. I should revise why that is.
You could try with CLOS instances instead of structs, but we should make it possible to access structs too.
I've spotted the problem in the access library. Doesn't work for structs.
Problem is here: https://github.com/AccelerationNet/access/blob/1f3440b03823e01bc6f1384daf18626234f86447/access.lisp#L181 and here: https://github.com/AccelerationNet/access/blob/1f3440b03823e01bc6f1384daf18626234f86447/access.lisp#L323
(structure-objects are not considered).
I'll make a pull request soon.
@mmontone thank you for the quick replies and quick solution. I could explore CLOS instead but my use case is using datafly which uses a defstruct model.
appreciate the help and explanations.
You have one more option: use the struct generated accessors. person-id
and person-name
.
So: {{person.person-id}}
in your template.
I've tested it and it works.
If you still get NIL, make sure that *djula-execute-package*
points to the package that defines your structures.
If you find Djula too troublesome you could consider TEN, my another attempt at a template system for Lisp, that is more flexible than Djula. (you would still have this accessing problem though, as it is a problem with access library)
Structure accessing has been integrated into the access
library.
Is it possible to reference struct accessors from the template?
I am moving from treating my lists as
(ID 5 NAME "fake")
using the template like the examples
{{ person.id }} {{ person.name }}
to person structures
#S(PERSION :ID 5 :NAME "fake")
but I cannot access the values when they are structures instead of key value pair lists.
I was just checking to see if this is possible before trying a different options.
Thanks for any clarifications.