as described here: https://github.com/plone/plone.app.textfield/issues/41
whenever adding a richtextfield to your custom type, you need to double check if the field isn't None, before getting its raw or output (relative or not - doesn't matter) value.
i guess this would be fixed by initiating richtextvalue even if its content is and empty (unicode-)string.
is there anything horribly wrong by following this approach?
is it hard to achieve?
would it break anything into pieces?
hope for a little discussion upon that.
In general true. On the other hand, handling this issue in a template using
context/text/output | nothing is a no-brainer.
i know, this is not a major blocking issue and i know how to handle it, but ...
an issue, i have to handle each time, is an issue i want to see solved, not handled each and everytime.
i stumble upon this from time to time and most recently in a collective project.
not to blame someone. just to say: this happens and is not necessary.
If your view extends
from plone.dexterity.browser.view import DefaultView then you can use
<div tal:content="structure view/w/details/render" /> in your template, which should handle this automatically.
See also https://docs.plone.org/external/plone.app.dexterity/docs/custom-views.html#display-view
as said before, how to fix this in the very last step is well known.
i still think its worth a look having this solved in the very first step: when creating a richtext object.
if, could, should.... can't we make it a bit more painless with such a simple pr? +1 from me
The thing is that you by default shouldn't be using
.output anyhow as it doesn't revolve relative links in the right context.
The "right way" is to do what the default display widget does, which means you'll have to type more stuff anyhow. Like https://github.com/plone/plone.app.textfield/blob/bcc52c70dcb4e0a36b95629a74806159c09ea50e/plone/app/textfield/widget_display.pt#L17
Side note: you could add a default value (empty string), which should give you a RichTextValue be it empty.
Now I'm not sure what happens if you have an optional field. Optional fields in zope schema land will give you a None for any field, so you need to check for that.
maybe i did not explain it correct, but you are talking about the template and that only.
i am seeking and proposing a solution for python and templates.
this is exactly where i stumbled for example:
having richtext with a value and then emptying it - store that and you get "None" and have to check for the values very carefully.
you could be more carefree, when a richtext is a richtext, no matter, if empty or filled with whatever.
the holy trinity of questions to get text displayed - i know that
but what about that once and for all:
or in python
if value and value.output_relative_to(view.context):
i actually don't like to ask a richtext to be richtext in order to do richtext stuff with it.
but maybe its a wish from z3c.form to have to ask that.
on a generic field i'd understand that for sure.