Getting attributes from attributes list in define-tag-function
#61
Closed
opened 4 years ago by merriman-xyz
·
2 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Have been playing with Pollen for a bit and after the basics have been trying more advanced features.
Currently I am trying to create a section class that creates a
<section>
tag with an inner<h2>
tag that uses the text of the parent section's id.In other words, take the following Pollen markup:
and output the following HTML:
My current attempts have been via
define-tag-function
. I have been able to nest theh2
tag, but am having trouble accessing the attributes list and grabbing the id for the innerh2
tag there. Ideally I could grad the ID and transform it into title case.Any help would be appreciated!
In your
section
tag function,attributes
will contain a list of keys/values. In this case it will be'((id "TITLE"))
. You can use Racket’sassoc
function to grab the things you want out of there. So, for example(first (assoc 'id attributes))
. An even easier way would be to use theattr-ref
from thetxexpr
package.(attr-ref attributes 'id)
does the same thing as theassoc
example above.Thanks @otherjoel for the lucid explanation.
Installed
txepr
viaraco pkg install txexpr
and was able to extract the value of theid
attribute with ease.Lovely being able to build components out of a single command.