I'm not sure if this is possible or if it is how to go about it. I have a lot of labels that I am creating using data merge. Certain text fields require a label like this…
Label 1: Merged text data
Label 2: Optional merged text data
Label 3: Optional merged text data
Label 4: Optional merged text data
I have a number of different label styles where the sometimes the label is not used and sometimes it may be a different layout, such as above the merged text. So I have kept the label out of the data and simply hard coded it into the merge template. So I had to create a number of variations for each layout if it has label 1 and 3 but not 2 etc.
I aslo have empty line removal, the hard return will be removed if empty.
So I wonder if it is possible to use Grep to check if text exists for a certain field and conditinally add the styled label text. So I could reduce my template variations. In all I have a bout 5 fields that require this.
The following text is technical, and varies, such as
AWS/ASME-SFA A5.18 ER70S-6
AS/NZS 14341-B G 49A 3U C S6, G 49A 3U M S6
I could only see it working if it was possible to test in a very general sense if there was text there or not.
I know I could add label fields in Excel, but it's a pretty complex spresdsheet already and I was hoping to avoid adding more columns to it if possible. It's frustrating that this sort of conditional stuff is easy in something like Word but InDesign's merge functionality is practically unchanged from the it's origins in Pagemaker.
ID does have Conditional Text, which may also be another option. Conditonal text is shown or hidden globally, and the same text can, I believe, carry more than one condition.
But that still leaves trying to test to apply the conditions, or doing it manually (by some sort of code in the data) before the merge. If you know all of the possible combinations of following text I'm sure this can be scripted, but the effort involved is probably more than adding the columns to the spreadsheet.
Thanks for the suggestions Peter, I had looked into conditional text but as I understand it is more akin to layers. You create a condition yourself, apply it to a text selection and then make that condition visible or not literally like a layer within a text block. Good for language variations etc in one document but I don't think it can be used for this.
If I put a code in the data source then I may as well just add the labels.
And as the data varies quite a lot I was after a general test for non empty state rather than scripting in tests for every specific text variation. Looks like I'll just have to add more columns to my spreadsheet. Groan, 800+ line items.
So maybe I'm not really understanding the problem.
You can use a look-ahead in GREP, perhaps, but I'm not quite sure what you want to look for. You could find blank lines, but it would be difficult to differentiate between different non-blank lines.
Maybe using unique paragraph styles for each label? GREP can't find text in one style followed by another, but scripting can, I think.
I was basically wanting to test if the line has text in it put in the label, if it's empty no label. I understood this would mean a separate paragraph style for each type. In the end I just added extra columns for the label names in excel and added extra field in Indesign.