Previously, we have seen how to declare a variable using the tag ‘assign’. Capture does a similar thing as it also creates a local variable in our template. The main difference here is that capture can include a combination of plain text and variables. Another thing to consider here is that variables that are created using capture are always stored as strings in our database.
Unlike assign, capture tags need to be opened and closed
We write the variable name next to the word capture
Then we include the code we want to capture after the opening tag.
Finally, we close the capture with the endcapture tag
It’s important to follow a set of rules when naming variables in order to keep consistency and make our code more readable:
Variable names should always be in lowercase
Different words should be separated by an underscore (_) rather than a blank space (spaces are not allowed in variable names)
Variable names should never start with a number.
Variable names should be descriptive.
Updated over 2 years ago