Methods for Working with the Register
Register set
With the command register_set you can directly set the value of the register. It is also possible to use variables and arguments to substitute data in a value. Since the register exists only in a block context, you can use this command only in a block context.
Below are examples of using register_set in the code:
- find:
path: a.somepath
do:
# PARSE TEXT CONTENT OF CURRENT BLOCK
- parse
# REGISTER CONTENT NOW: "Link"
# LETS ADD PREFIX "URL:" TO THE VALUE OF THE REGISTER
# ITS EASIER TO DO IT USING SPECIAL VARIABLE CALLED <%register%> WHICH CAN BE USED TO SUBSTITUTE THIS TAG WITH CURRENT REGISTER VALUE
- register_set: "URL:<%register%>"
# REGISTER CONTENT NOW: "URL:Link"
# LETS SET FOLLOWING VALUE TO THE REGISTER: "There is no link"
- register_set: There is no link
# REGISTER CONTENT NOW: "There is no link"
# SAVE REGISTER VALUE TO THE VARIABLE `somevar`
- variable_set: somevar
# NOW VARIABLE `somevar` HAS VALUE "There is no link"
# LETS USE THIS VARIABLE IN THE REGISTER_SET COMMAND
- register_set: I was looking into HTML. <%somevar%>
# REGISTER CONTENT NOW: "I was looking into HTML. There is no link"
Let's now look at how to modify the data in the register using different commands.