I have a Plone 4 site where I currently use the following method to embed objects (e.g. images, videos, tables …) in user-editable HTML content:
- I have a custom
transformbrowser which takes HTML text and transforms allaandimgelements which refer to an element by UID (i.e., which have anhref="…/resolveuid/abc123…"orsrc="…/resolveuid/abc123…"). - My view templates read the
textfield and let that browsertransformit; - the browser has a Python dict
TYPE2TEMPLATEwhich hasportal_typekeys andtemplate_idvalues; - for each
aorimgwhich refers to an object by UID,- the object is fetched by
o = brain._unrestrictedGetObject() - the template id
t_idis taken from theTYPE2TEMPLATEdict - the "embed" method is fetched by
method = o.unrestrictedTraverse(t_id) - that method is called (in some cases with some keyword arguments), and the result - which is contained in one top HTML element - replaces the "raw"
aorimgelement.
- the object is fetched by
Now that I'm developing an additional customization package (which contains new object types, now using Dexterity), I wonder whether there is some more "plonish" way. Is there, for example, some embed action?
i don't know of a package that does the same and what you're doing sounds sane to me ;-)
i just would use https://pypi.python.org/pypi/plone.outputfilters instead of your
transformBrowserView.if it's possible to explicitly mark links that should not be auto-embedded (eg via
span.noEmbed a.internal-linkselector) this could become a useful addon.i guess for portal_type=='File' you'll need to check the mimetype too in order to decide if you're embedding a video file or something else...
other products i know of embed content outside of your plone site (eg. collective.embedly)
another approach would be a to use a tinymce plugin to genereate the proper embed html when editing the html-body of your page (i personally would not go this route because there are different tiny versions to support for 4.3 and 5.0 and we're not sure if tiny woun't be replaced as default editor in the future)