Skip to content

Access / add attributes in a filter #10177

Answered by tarleb
pagiraud asked this question in Q&A
Discussion options

You must be logged in to vote

Lua allows to use my_table.key as an alias for my_table['key'], i.e., it looks key up in table my_table. However, this works only if the key is a Name, which the Lua manual defines like this:

Names (also called identifiers) in Lua can be any string of Latin letters, Arabic-Indic digits, and underscores, not beginning with a digit and not being a reserved word. Identifiers are used to name variables, table fields, and labels.

Thus, background-image is not a name, which means that square brackets have to be used:

blocks[i].attributes['background-image'] = "img.jpg"

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pagiraud
Comment options

Answer selected by pagiraud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants