"Trim" an empty string out of existence?

Options

Is there a filter that I can "trim" an empty string into null or just completely out of existence?

Other than a conditional to handle this and just set the value to null.

Comments

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Is this string a variable or field in an object?

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    One of things I can think of is to check it with filter is_empty and the use "replace" to turn true into null

  • Brian Giometti
    Options

    It's more complicated, but in this case its a field in an object that's getting two other fields concatenated. I just want to set it to null if both of those fields are null, rather than set it to a space (the separator) or empty string (if I apply trim). There are other similar uses I can see for this.

    Right now I've just got a conditional after this variable assignment that checks if its an empty string and sets null, but it feels clunky.

    One other use I've got that I havent dealt with is pushing parameters to an existing array, but I don't want to push empty strings either. This same (probably non existent) filter would be handy for that too.

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Ok, so regarding the first thing. I think this should work. update parameter in you object with set_conditional with condition that right now it is empty.

    Regarding pushing empty parameters to a list, after you push all of them you can use filter - "filter_empty" to get rid of the empty ones