Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EXAMPLE ARRAY:
- <cms:set populated_authors__array = '
- {
- "26b3eed025edc2ef22a0466bab45ae57" : {
- "page_id" : "18",
- "name" : "Ray Bradbury"
- },
- "60ee1ca285beb8348406446e56e6cda4" : {
- "page_id" : "19",
- "name" : "Isaac Asimov"
- }
- }
- ' is_json='1' scope='global' />
- -- Variable '_input_author_hash' comes from CSV_READER and I create a hash of it to avoid string comparison
- <cms:set _input_author_hash = "<cms:md5 _input_author />" scope='global' />
- -- Next, we check if that hash is already in my list of Authors in CMS
- <cms:if "<cms:arr_key_exists key=_input_author_hash in=populated_authors__array />" >
- -- Author already populated and stored in array, thus I know its k_page_id -->
- <cms:set related_author_id = "<cms:get "populated_authors__array.<cms:show _input_author_hash />.page_id" />" />
- -- Otherwise add a new Author to the list:
- <cms:else />
- -- creates a new page with this Author
- <cms:db_persist _masterpage='related_authors.php' .... />
- -- saves 'k_last_insert_id' into 'populated_authors__array' variable:
- <cms:set related_author_id = k_last_insert_id />
- <cms:set populated_authors__array. = _input_author_hash scope='parent' />
- <cms:put "populated_authors__array.<cms:show _input_author_hash />" "[]" is_json='1' scope='parent' />
- <cms:put "populated_authors__array.<cms:show _input_author_hash />.page_id" related_author_id scope='parent' />
- <cms:put "populated_authors__array.<cms:show _input_author_hash />.name" _input_author scope='parent' />
- </cms:if>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement