Is there a way to "reuse" (or "import" or "include") Dexterity Type definitions (XML)?

We have different Dexterity Types which share most of the properties defined in profiles/default/types/MyType.xml.

Is there a way to define the shared properties in an extra xml-file and to "import" or "include" them into the different type definitions?

Or (alternatively): is it maybe possible to remove the properties from the MyType.xml file and define them in a class?

Usually, you would do this using XInclude. I am not sure about the underlying code doing the XML parsing and handling. If it uses lxml, then there is a chance that XInclude could be supported...you need to try that out.

I would put all fields (if that is what you mean) in a behaviour, and then enable it on all content types you want to use.

That said: It is also possible to import an xml in your content types py file.
If you make a content type with plone-cli there will be a comment about how to do that

@zopyx: The XML file is loaded by Products.GenericSetup and it uses xml.dom.minidom.parseString.
It seems that parseString ignores the functionality of <xi:include ...>. :frowning:

@espenmn: I've searched for the comment you mentioned. But cannot find any. Could you please give me another clue how to import an xml file in my content types py file? Or maybe a link to an example?

Maybe the import is from the xml file.

Try this with plone cli (I am at home, so I can't test)

  1. Add a content type and answer XML
  2. Add a content type and answer py
  3. Look in all files in /content and look for an 'import line'.

Any reason you dont want to do it with a behaviour ?

Note: plone cli can add behaviour, then you just add it to your content type (in profiles/types/your_type, I think

That's why it is called mimidom :clown_face:

@espenmn: As far as I understand it, your proposal is intended for loading the model (fields, widgets etc.). This of course could be done with a behaviour.

Nonetheles this is not what I am searching for. I'm searchig for a way to define the fti properties and include or import them. I'll describe the issue in detail:

Having content_types TypeA, TypeB, TypeC ... which share e.g. the properties filter_content_types and allowed_content_types the "normal" way is to define those properties in every XML-file. So the following
xml-code would be duplicated in TypeA.xml, TypeB.xml, TypeC.xml etc. and wenn we need to change it, we must change it in every fille TypeA.xml, TypeB.xml, TypeC.xml etc.

# code in TypeA.xml, TypeB.xml, TypeC.xml etc.
<object meta_type="Dexterity FTI" ... >
  ...
  <property name="filter_content_types">True</property>
  <property name="allowed_content_types">
    <element value="SomeType"/>
  </property>
  ...
</object>

@zopyx pointed to the possibility of xi:include the properties. This is not working due to the way GenericSetup loads the xml-file (minidom). This would - if it had worked - look like the following.

# code in TypeA.xml, TypeB.xml, TypeC.xml etc.
<object meta_type="Dexterity FTI" ... >
  ...
  <xi:include href="shared_properties.xml" />
  ...
</object>

# code in "shared_properties.xml"
  <property name="filter_content_types">True</property>
  <property name="allowed_content_types">
    <element value="SomeType"/>
  </property>

Are maybe there some ways to define the FTI other than the xml-file? Is the FTI accessible from some part in the addon? Can this maybe be done via Behavior?

Sorry: I think I misunderstood the question the first time.
(so I have never tried what you try to do)

A wild, wild guess: Could you work around it by loading the 'settings' instead of loading the xml, something like:

<element value=some variable" />

I think there is something called <xsl:variable , not sure if it would work

@espenmn Thanks for your hint!

I imagine you mean using <!DOCTYPE doc [ <!ENTITY includeFile SYSTEM "include_file.xml"> ]> and &includeFile;

Unfortunately this is not supported by minidom.

Plone Foundation Code of Conduct