CSV Data Source Record Set Keyword as a Modifier Parameter


(Lewis) #1

Any idea why the following doesn’t work? %begin_globals_get_town^eq:Medway% works but substituting {ds__town} doesn’t. %ds__town% returns ok

%begin_globals_get_town^eq:{ds__town}%
    Yes
%else_globals%
    No
%end_globals%

(John gill) #2

because %globals_ keywords are processed later than %ds__ (and %asset_) keywords, so by the time the conditional keyword is actually handled the meaning of %ds__ is lost.

The first thing I’d try is to flip the keywords and see if

%begin_ds__town^eq:{globals_get_town}%
    Yes
%else_globals%
    No
%end_globals%

works.


I think this keyword construction should throw a warning when saved, this is the most common keyword misunderstanding I see by a wide margin.

Anytime you’re using an early processed keyword as a replacement keyword in a late processed keyword you’re liable to get nothing at best, and misleading behaviour at worst (things that look like they work, but they’re working for a different reason than you think which blows up in your face down the road).


There are plenty of cases where %late:{early}% seems to work, but as far as I can tell in those cases you could more accurately construct them in a %late:{late}% fashion.

e.g.

%globals_get_blerp^replace:example:{asset_name}%

might work sometimes, but in those cases it would be less ambiguous to write it as

%globals_get_blerp^replace:example:{globals_asset_name}%

As far as I know, the latter keyword is a more accurate representation of what Matrix actually does when it processes it.


(Usual disclaimer that I’m wrong about heaps of things every day, and I might be missing something, but if anyone has an example of a %late:{early}% keyword that both works and isn’t better expressed as %late:{late}% then I’m very keen to see it)


(Lewis) #3

Hi @JohnGill. I’ve tried flippiing it around as you suggested but it doesn’t work.

Essentially I’m trying to filter a list of community groups by town. I know this is possible with a straight Asset Listing but I’m led to believe (from the manual) that this is only possible when the records are grouped into folders - something that it isn’t really practical to do when you’ve uploaded a CSV file, especially for the content writer with less technical knowledge.

Any ideas? Do you have a link to Squiz’s documentation where processing order is mentioned? I’m sure I’ve seen it but can’t find it now.


(John gill) #4

I just tried a sample to check, and at least for a test case it can work.

Using a CSV Data Source that contains

name,category
apple,fruit
banana,fruit
carrot,vegtable
date,fruit
escargot,meat
fig,fruit
goat,meat

and an Asset Listing Page that contains both versions of the conditional block

%begin_ds__category^eq:{globals_get_category}%
    <li>%ds__name%,%ds__category%        <b>early{late}</b> </li>
%end_ds%

%begin_globals_get_category^eq:{ds__category}%
    <li>%ds__name%,%ds__category%        <u>late{early}</u> </li> 
%end_globals%

then I request the page with ?category=meat and I see

  • escargot,meat early{late}
  • goat,meat early{late}

(testing on 5.5.6.2)

Obviously there could be any number of other factors going on, but it should be possible to compare a CSV data source value to a %globals_get param if you put the data source value first.


The only reference for execution order I know of is https://matrix.squiz.net/manuals/concepts/chapters/server-side-javascript#processing-order . It doesn’t refer to the late{early} issue directly, but you can see how it would happen.


(Lewis) #5

Hi @JohnGill. Thanks again for taking a look at this. The {late} one works for me and the {early} one doesn’t. The only difference I can see between this code and your earlier code is that you’ve closed out the %end’s with %end_ds% etc instead of %end_globals% (the earlier code didn’t work).

It’s working now anyone so thanks for taking the time to help! :blush: