How to insert newline into the diagram using preprocessor?

0 votes
asked Jul 2 in Question / help by dragondive (520 points)

I draw a grid like this:

https://www.plantuml.com/plantuml/uml/BSqX3e0m341HtrCimIBMzWAxoX9m0y6A0kxEyZFppHE_zAXNt4UJNbl8iqXARyfhfagDEgA88ehe54CCCSIcEEA88pxaaxAVspZ_

PlantUML diagram
Now I would like to generate it using the preprocessor, but it doesn't work because I cannot seem to put a newline into the generated diagram to separate the "rows":

https://www.plantuml.com/plantuml/uml/SoWkIImgAStDuIfEp2dXgbRcKb1GLCbJi5Km0REAyik1R0CGkpmZCoTL0InYew2I1nG2AKZEpodDpOEgWQk22aCLWa4DMAiEH0OaYAOVnj9MC8IOb9gN0ZOCp5FDIotFoSnBrT04SX4E0r5G7GZrjLmEG3RGJm00

PlantUML diagram
I do not necessarily need "salt" for this. I also tried the title "table" from the docs: https://plantuml.com/preprocessing#f8d8089a98ca8958. But this also has the same problem with entering a newline into the generated diagram.

I tried using the %newline() function, inserting \n, but I can't get it to work.

What is the proper approach to insert a newline into the generated diagram using the preprocessor?

1 Answer

+1 vote
answered Jul 2 by The-Lu (67,000 points)
selected Jul 3 by dragondive
 
Best answer

Hello D.,

For that you can use function, as:

@startuml
!function $myfunc()
  !$n = 4
  !$row = 0
  !$res = ""
  !while $row < $n
    !$column = 0
    !while $column < $n
      !$res = $res + "| "+ $row + "," + $column
      !$column = $column + 1
    !endwhile
    !$res = $res + %newline()
    !$row = $row + 1
  !endwhile
  !return $res
!end function

salt
{#
$myfunc()
}
@enduml

- But what are your mean goal?
Just to create an 2D array?

Enjoy,
Regards,
Th.

commented Jul 2 by dragondive (520 points)

@Th. Thank you, I'll try this.

- But what are your mean goal? Just to create an 2D array?

I'm working on something that is (I think) fun and educational. The 2D array in this question is a cut down version of my actual problem. I'll share here and with the community when I have it ready. 

...