Using replace_keywords to index JSON


(Cameron Martin) #1

Matrix Version: 5.3.0.0

I have a REST Resource Asset (with ID 1560461) that returns the following JSON:

{"react_root":"<div data-reactroot=\"\">This is a part of page 1 rendered using React.<\/div>"}

Inside a Standard Page asset, which is nested under another standard page, I have the following:

<div id="%nested_get_element_id%">
    %globals_asset_contents_raw:1560461^json_decode^replace_keywords:index:{nested_get_element_id}%
    
    %globals_asset_contents_raw:1560461^json_decode^replace_keywords:index:react_root%
    
    %globals_asset_contents_raw:1560461^json_decode^index:react_root%
</div>

This gets rendered as the following:

<div id="react_root">
    {"react_root":"<div data-reactroot=\"\">This is a part of page 1 rendered using React.<\/div>"}
    
    {"react_root":"<div data-reactroot=\"\">This is a part of page 1 rendered using React.<\/div>"}
    
    <div data-reactroot="">This is a part of page 1 rendered using React.</div>
</div>

As you can see, when indexing the JSON without using replace_keywords, it works fine, but when I introduce replace_keywords, even with a static parameter, the whole keyword modifier is ignored and the JSON does not get indexed.

Can anybody shed any light on why this is happening, and if there is a workaround?


(Bart Banda) #2

Not sure, 5.3.0.0 is a quite old version, so there may be some bugs or missing functionality to what you are trying to do.

I would instead try and handle it all in the REST asset, and actually use a JS REST asset instead so that you can pass the %nested_get_element_id% value into the JS processing and extract the correct string using just JS?