Paint layout on data source records


(Buttrose) #1

This is one that has been asked before but none of the solutions I've seen seem to work.

 

The problem: you have a data source, say JSON, and make an  asset list of the data source records.

You can put a Default Format on the list that will set the display of the individual records - you can use keywords,including  field value keywords, etc.

Well and good. Works fine, but type formats in asset listing can't contain conditional logic, either  conditional keywords or directly code conditions.

As I commented in a previous post, this just seems an oversight - no good reason whatsoever it has not been implemented. And you need it! If there are empty fields in the JSON you want to ignore any associated display.

 

The solution in other cases (where you are listing standard pages or news items for example) is to use a  paint layout (which can contain conditions).

To do this , you put a keyword of the form %asset_contents_paint_xxxx% where xxxx is the asset id of a paint layout e.g. %asset_contents_paint_1546946% in the default format of the asset listing.

For data source records,  however, this does not work. Nothing is displayed. Is this because data source records are "ghost assets" or some nonsense as another poster has claimed?

 

 

It is very frustrating trying to get this to work. As some may have guessed, I'm a developer used to writing sql and formatting the results in a scripting language, thus doing in 5 minutes what I've spent days figuring out how do in Matrix.

 

Any help appreciated.


(Buttrose) #2

No one knows anything about this?

 

OK, simpler question. How do you apply a paint layout to a data source record set and does it work?


(Buttrose) #3

Using  javascript to remove empty elements from the DOM is one, not very satisfactory, solution to the conditional display problem.


(Tim Davison) #4

I sense (and often share) your frustration.  Often the issue with developing with a CMS (and this is not specific to just Matrix) is wrestling with the system to get it to do what you want.  If you've come directly from a SQL+sever-side background you probably had very powerful access to the underlying data, may have a very strong if-else coding paradigm, and so may need to learn alternative approaches (I commiserate this will feel like pulling teeth at first, and maybe forever, but if this is the CMS you're working with need to learn to work with it).  A post I wrote some time ago that may get you some of what you want:

 

http://forums.squizsuite.net/index.php?showtopic=12591&p=54761

 

I should add that in later versions (my post was targeting v4.12) there has been a lot of functionality added that may be useful, specifically around 'replace_keywords', which I now use extensively to avoid design customisations and paint layouts (both of which I avoid like the plague - possibly just old habits).  For example:

<!-- display a callout if there is intro text, otherwise nothing -->

%asset_metadata_Layout.IntroText^replace_keywords:notempty:
<div class=“intro-text”>
<p>{asset_metadata_Layout.IntroText}</p>
</div><!-- /.intro-text -->
^trim%

Something else that has improved a lot in later Matrix versions is applicability of keywords in more locations.  E.g. in some earlier versions the methods I've described above did not work in certain bodycopies but did in others (e.g. not working in an Asset Listing Page Contents but works in the same listings Type Formats).  I noticed this as a particular issue with Data Record Sets, so that's something else to send you barking mad.  Again, much improved in later versions.


(Peter McLeod) #5

Hi

 

Could also play around with the tagif keyword modifier - might be ok for simple requirements:

 

For example:

%asset_metadata_FieldName^tagif:p class="class_name"%

would result in html below if there is a metadata value:

<p class="class_name">Metadata Value</p> 

Or nothing if there is no value.

 

Peter


(Tim Davison) #6

Wow, I didn't know you could put attributes into tagif.  Does it work with all attributes?


(Peter McLeod) #7

Hi Tim

Seems to work ok whenever I've used it, don't think there's any reason why it shouldn't work with other attributes if the example above works.

Not sure if it has always been the case - or just in more recent versions.

Peter


(Tim Davison) #8

My testing is giving invalid HTML, I get the following:

<p class="class_name">Metadata Value</p class="class_name">

Most browsers can figure this out and just ignore the erroneous stuff in the closing element.  Tested in Matrix v5.1.

 

Wonder if this would be a good enhancement request.  Surely it wouldn't be that hard to strip out the extra stuff after the tag name.  It would literally be everything after the first space inclusive.


(Peter McLeod) #9

Hi Tim

 

Yeah it's a matrix version issue - I'm using 5.1.9. I just checked the release notes.

 

In v5.1.6.1 the docs say:

 

https://manuals.matrix.squizsuite.net/releases/5.1.6.1

 

Time to upgrade! :)

 

Thanks

Peter


(Tim Davison) #10

Nice one.  We've got upgrades coming soon(ish).  Looking forward to being able to use it.  Cheers mate.


(Bart Banda) #11

This is one that has been asked before but none of the solutions I've seen seem to work.

 

The problem: you have a data source, say JSON, and make an  asset list of the data source records.

You can put a Default Format on the list that will set the display of the individual records - you can use keywords,including  field value keywords, etc.

Well and good. Works fine, but type formats in asset listing can't contain conditional logic, either  conditional keywords or directly code conditions.

As I commented in a previous post, this just seems an oversight - no good reason whatsoever it has not been implemented. And you need it! If there are empty fields in the JSON you want to ignore any associated display.

 

Conditional logic in type formats should also work, probably a bug that has been fixed since your version, I use them all the time in asset listing type formats.