This is going to sound fairly basic, but I'm tryin...
# general
r
This is going to sound fairly basic, but I'm trying to (manually) pretty-print a table for output in a Slack code block. Doing this means I need to insert some number of spaces between values. I've got a
for
loop to do this, because AFAIK there isn't another way to insert an arbitrary number of spaces. Unfortunately, some sort of optimization seems to be taking place, because
{% for i in (1..spaces_needed) %} {% endfor %}
or
{% for i in (1..spaces_needed) %}{{' '}}{% endfor %}
result in just one space, but
{% for i in (1..spaces_needed) %}x{% endfor %}
results in
spaces_needed
copies of
x
. Is this a bug in Tines? In Liquid? In my code?
It also appears that using
*
instead, and then doing a
replace: "*", " "
also optimizes away sequential spaces.
a
@modern-farmer-99434
m
I actually think this is just a display issue Jeremy!
If you look at the raw event, it should be printing the spaces, but i think we try to optimize the display in Tines to show only one space
there does have to be something in the forloop though, so that looks to be causing an issue
here's two examples anyway:
Copy code
{
  "agents": [
    {
      "disabled": false,
      "name": "List",
      "options": "{\"mode\":\"message_only\",\"loop\":false,\"payload\":[\"dog\",\"cat\",\"mouse\"]}",
      "position": {
        "x": 945,
        "y": 285
      },
      "type": "eventTransformation"
    },
    {
      "disabled": false,
      "name": "set message with xyz",
      "options": "{\"mode\":\"message_only\",\"loop\":false,\"payload\":{\"message\":\"x{%for item in list%}xyz{%endfor%}x\"}}",
      "position": {
        "x": 945,
        "y": 405
      },
      "type": "eventTransformation"
    },
    {
      "disabled": false,
      "name": "replace xyz",
      "options": "{\"mode\":\"message_only\",\"loop\":false,\"payload\":{\"message\":\"{{set_message_with_xyz.message | replace:'xyz', '   '}}\"}}",
      "position": {
        "x": 945,
        "y": 540
      },
      "type": "eventTransformation"
    },
    {
      "disabled": false,
      "name": "List",
      "options": "{\"mode\":\"message_only\",\"loop\":false,\"payload\":[\"dog\",\"cat\",\"mouse\"]}",
      "position": {
        "x": 1170,
        "y": 285
      },
      "type": "eventTransformation"
    },
    {
      "disabled": false,
      "name": "set message with x",
      "options": "{\"mode\":\"message_only\",\"loop\":false,\"payload\":{\"message\":\"x{%for item in list%}   x    {%endfor%}x\"}}",
      "position": {
        "x": 1170,
        "y": 405
      },
      "type": "eventTransformation"
    }
  ],
  "links": [
    {
      "sourceIdentifier": 0,
      "receiverIdentifier": 1
    },
    {
      "sourceIdentifier": 1,
      "receiverIdentifier": 2
    },
    {
      "sourceIdentifier": 3,
      "receiverIdentifier": 4
    }
  ],
  "diagramNotes": []
}
the first is doing a forloop with xyz then replacing
xyz
with three blank spaces; the next is including an
x
in the centre
so it looks like the forloop will strip all spaces unless there's something else in there
r
Interestingly, so does
replace
I tried doing it where I put in
*
instead of spaces, and then piped it through
replace: "*"," "
and that also stripped all but one space.
(Wouldn't it be nice if Slack mrkdwn had a table primitive so I didn't have to pre-format text for it?)
m
can you check if it strips all but one space in the raw event too? There's definitely a UI thing there
This is definitely awkward and not easy to find though!
r
Sorry if I was unclear - I'm testing with just a raw
message only
action
And looking at the dry run output directly
m
So try “run” instead of dry-run and then look at the raw event
I think some of the challenge is displaying it within Tines where Tines will strip some spaces
r
oh, I can confirm that what comes through to Slack also has the stripped spaces.
m
But if you view the raw event it included the spaces
r
Yeah. I just did that as a test, and the raw event does not include the spaces.
If the problem were just in string handling in
for
loop output, I would expect a
replace
operation to work normally, but I can't seem to replace with just spaces, either.
I take that back, I just re-did it (again) with
*
inside my
for
loops, then a
replace
operation worked to change them to spaces. It didn't yesterday. Baffled but my problem is resolved.
m
Phew
I was really scratching my head there cause I got that working
Thanks for your patience with this Jeremy! I’m glad you got it working!
I’ll flag this to the engineers to dig in on, we might be able to find an elegant solution
r
This is something where it might be nice to have some functions around pretty-printing data in various formats might come in handy. I could see use cases in Slack, Email, etc.
I just re-read the above and wow, I'm not coherent this morning. But you get the idea.
m
I do!
r
Time for another