Formatting a data source record set


(G Schmidt) #1

I'm trying to do something fairly straightforward, but it doesn't seem to be possible so I'm probably missing something.

 

I just want to retrieve JSON data dynamically from a web service, and then produce a web page based on this data.

 

The closest I have gotten so far is:

1. I've created a REST Resource which retrieves the data

2. I've created a JSON Data Source, connected to the REST Resource

3. I've set up an Asset Listing Page, connected to the JSON Data Source

 

Now I can output fields from the JSON data, by inserting %ds__ keywords into the Asset Listing's Default Format template, and this works.

 

But I don't think this approach is going to let me do what I want. I need to be able to use conditional logic in the output template. eg. if a certain JSON field is empty, skip a whole chunk of output.

I understand that Paint Layouts can do this. But I haven't been able to figure out a way to format data source records using a Paint Layout.

 

Any advice would be much appreciated.


(Nic Hubbard) #2

Have you tried applying a Paint Layout to your Asset Listing? And then edit the Conditional Keywords screen?


(G Schmidt) #3

Hi Nic, yes I tried to do this, but I could only apply a Paint Layout to the Asset Listing as a whole, not the part that repeats for each record. So any %ds__ keywords in the Paint Layout were not being replaced.


(Nic Hubbard) #4

Hi Nic, yes I tried to do this, but I could only apply a Paint Layout to the Asset Listing as a whole, not the part that repeats for each record. So any %ds__ keywords in the Paint Layout were not being replaced.

 

In the Type Format for your asset listing, you need to use the %asset_contents% keyword, which then allows you to use the Paint Layout's Type Format to control the listing.


(G Schmidt) #5

So currently I have:

  • My Asset Listing > Type Formats > Default Format is set to 
    %asset_contents%
  • My Asset Listing > Page Contents is set to 
    %asset_listing%
  • My Asset Listing > Lookup Settings > Paint Layout is set to My Paint Layout
  • My Paint Layout > Type Formats > Default Format is set to 
    <p>The title of this record is %ds__title%.</p>

    ('title' is one of the fields present in every data record)

 

But when I preview the asset listing, all i see in the body of the page is 'The title of this record is %ds__title%.' (ie. the keyword is printed verbatim).

 

If I instead use the keyword inside My Asset Listing > Type Formats > Default Format, it gets subsituted correctly, so it isn't a data lookup problem.


(Nic Hubbard) #6

What version of Matrix are you on? I just tested it and it works for me on 4.18.2.


(G Schmidt) #7

This is on 4.18.3


(Nic Hubbard) #8

This is on 4.18.3

 

Make sure to set the Asset Type of the Paint Layout to Data Record Set. That is how I set it up and it worked.


(Amurray) #9

can confirm working using "Data Record Set" - no paint layout (just yet)

 

Cheers Nic!


(Kieran) #10

Hi Nick, digging this up but I am on v6.26.1 and have the same issues as @glenn above.
The Paint Layout doesn’t have the option for “Data Source Record Set”, just the different types of “Data Source” and “Data Record”.
So it defaults to the Default type format and keywords do not resolve in the paint layout - they just appear as literally written.


(Mark Nearhos) #11

Hi Kieran - FWIW I dont see “Data Source Record Set” as an option for Paint Layouts in v6.17.1 either.

However if you are only using the Paint Layout for the conditional logic, you can now do this directly in the Default Format body copy or the Data Source Record Set Format body copy.

%begin_ds__title^contains:ABC%
 Title has ABC
%else_ds__title%
 Title has no ABC
%end_ds__title%

Or
%ds__title^contains:ABC:Title has ABC:Title has no ABC%