This concept is extremely popular in my works, I can't imagine what coding was before it. ☺ So thank you again, KK!
As a small donation, please accept this tutorial that I compiled and wrote in additional content with more examples -
Core Concepts » Couch Arrays
- Multi-level variables or Arrays
- - Syntax
- - Setting arrays
- - Iterate arrays
- Practice
- - cms:capture vs. cms:set
- - Objects vs. Arrays
- - Adding to arrays
- - Dynamic values
- - - Escaping
- - - Multi-word keys
- - - cms:get and cms:put
- - - Loops
- - Tags
- - Related tags
- - Related pages
- - -
This post is about a small tip that comes out of a following problem:
Q: Was array already set somewhere beforehand or it does not yet exist?
The question above may be answered with a set of 'conditional' tags: If exists.. use it.. otherwise ..create it.
Avoiding a condition, there is a one-liner solution that gets existing array's value or creates a new one in global scope —
I've created, tested and used it successfully in one of my funcs (Cms-Fu » clock) that needed to add a value to a possibly existing array or create a new array to keep the value.
As a small donation, please accept this tutorial that I compiled and wrote in additional content with more examples -
Core Concepts » Couch Arrays
- Multi-level variables or Arrays
- - Syntax
- - Setting arrays
- - Iterate arrays
- Practice
- - cms:capture vs. cms:set
- - Objects vs. Arrays
- - Adding to arrays
- - Dynamic values
- - - Escaping
- - - Multi-word keys
- - - cms:get and cms:put
- - - Loops
- - Tags
- - Related tags
- - Related pages
- - -
This post is about a small tip that comes out of a following problem:
Q: Was array already set somewhere beforehand or it does not yet exist?
The question above may be answered with a set of 'conditional' tags: If exists.. use it.. otherwise ..create it.
Avoiding a condition, there is a one-liner solution that gets existing array's value or creates a new one in global scope —
- Code: Select all
<cms:set clock = "<cms:get 'clock' default='[]' scope='global' as_json='1' />" is_json='1' scope='global'/>
I've created, tested and used it successfully in one of my funcs (Cms-Fu » clock) that needed to add a value to a possibly existing array or create a new array to keep the value.