New line in table built with variables is ignored

0 votes
asked Oct 2, 2019 in Bug by Jesper

I am trying to built a table by using functions and variables (and use this information in the diagram). I have however experienced that I cannot and a new row in the table with this method. 

I have this:

@startuml
!global $table = "|= Field1 |= Field 2 |"
!function $row($value1, $value2)
%set_variable_value("$table", %get_variable_value("$table") + " \n | " + $value1 + " | " + $value2 + " |")
!endfunction

$row("row 1", "2")

title
$table
end title
@enduml

However the result is one row with 5 cells

I had expected that the "\n" would create a new line

http://www.plantuml.com/plantuml/uml/TP2n2eCm48RtUuhVGq6fYza5fpv5GM9D9P16q6WN7xxNf4ANBk7Zo_5nNBS6lOJjwH3quCokbvMooSs3TiYZGWi-MbojSME3aw1mC6MFpT-3dJtoPNwL-QxTPfeQ2LH5nMf2Br7xAVNHbfowNAEO_lzMk81nypZ0WjzqbBz69SCLPSQFvpf4SH-M1mtNO2K356nmXbAVP1f9K2Si5tW3

When writing the table by hand it works as expected: http://www.plantuml.com/plantuml/uml/SoWkIImgAStDuIh9BCb9vL9GgB5LSCjCpKanXBCKZ1HgG18AHVdb2eOG6YoMcfUY0D7c06G23G40

1 Answer

0 votes
answered Apr 28, 2020 by The-Lu (63,920 points)
edited Apr 28, 2020 by The-Lu

Hello J.,

After some today's test:

I discover that: You can use your code (with only some suppression of extra space near '\n', and change 'function' to 'procedure'):

  • not with title 
  • but with Component or Deployment Diagram:

[Click to the image to view PlantUML code]

If that can help,
Regards,
Th.

commented May 3, 2020 by Jesper
Thank you very much, it works!
commented Nov 23, 2020 by Jesper
I assume something has changed in PlantUml as now neither my solution nor your example is working with the \n variable
commented Nov 26, 2020 by plantuml (294,960 points)

Yes, we have changed some things.

You have to use the %newline() function now :

@startuml
!global $table = "|= Field1 |= Field 2 |"
!procedure $row($value1, $value2)
%set_variable_value("$table", %get_variable_value("$table") + %newline() + "| " + $value1 + " | " + $value2 + " |")
!endfunction

$row("1", "2")
$row("3", "4")

rectangle r [
<i>on rectangle:
$table
]
@enduml

Hope this helps!

commented Jan 8, 2021 by Jesper
Sorry for the late answer, it is perfect, thank you!

I was not aware of that new function.
...