Custom Forms and Fields¶
Occasionally you may want to link some site entities (e.g. Polls, Articles) to certain sitetree items (as to categorize them). You can achieve it with the help of generic forms and fields shipped with SiteTree.
TreeItemForm¶
You can inherit from that form to have a dropdown with tree items for a certain tree:
You can also use a well known initial={'tree_item': 2} approach to set an initial sitetree item.
After that deal with that form just as usual.
TreeItemChoiceField¶
TreeItemChoiceField is what TreeItemForm uses internally to represent sitetree items dropdown,
and what used in Admin contrib on sitetree item create/edit pages.
You can inherit from it (and customized it) or use it as it is in your own forms: