7

I have two class diagrams in PlantUML and would like to define a class in one file and reuse it in the other. See the example below.

diagram1.puml:

@startuml diagram1

class "Foo" as foo {
 ...attributes
}

@enduml

and diagram2:

@startuml diagram2

!include diagram1!foo

class "Bar" as bar {
 ...attributes
}

@enduml

Now my expectation is that diagram2 will show me both classes Foo and Bar in the diagram. However, the included class is not shown in the render.

How can this be solved?

0

1 Answer 1

10

The plantuml include statement includes code as if it was typed in that included place (like include files for e.g C / C++ etc. do too). So the code should be like: For Diagram2:

@startuml diagram2

!include diagram1!foo

class "Bar" as bar {
 ...attributes
}

@enduml

and for diagram1

class "Foo" as foo {
 ...attributes
}

When you want also show diagram1 as a separate file you have to add an extra file with:

@startuml diagram1_show

!include diagram1!foo

@enduml
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.