Correct way to render an custom entity and its custom field?
View Builder



Set the view_builder in ContentEntityType annotation to EntityViewBuilder to inherit some default behavior (or write your own).


Set your canonical router to something like what content_entity_example does in the examples module.


Berdir suggests using DefaultHtmlRouteProvider though that class is marked as @internal so it may not be stable to use long term.




content_entity_example.routing.yml

entity.content_entity_example_contact.canonical:
  path: '/content_entity_example_contact/{content_entity_example_contact}'
  defaults:
    _entity_view: 'content_entity_example_contact'
    _title: 'Contact Content'
  requirements:
    _entity_access: 'content_entity_example_contact.view'




Change your entity theme to something like what node module does, and have it display as a render element. 


Use your entity or bundle's field display page to change what field formatters a given field will use.


Then you can print out {{ elements }} in the template for it to go through the entire render array for a given view mode. Again, you can follow something similar to node module.