Closed Bellfalasch closed 3 years ago
Hi,
I think the problem might be that libPortal.getContent()
shouldn't take Content
as it's type parameter. Try with Image instead.
Can this be what you are looking for?
import { Content, ContentLibrary, Image } from 'enonic-types/content';
const libContent: ContentLibrary = __non_webpack_require__('/lib/xp/content');
// ...
// const attachmentContent: Content<Image> | null = libPortal.getContent<Image>();
const attachmentContent: Content<Image> | null = libContent.get<Image>({ key: imageId });
log.info(attachmentContent?.data.media.attachment);
Another little tip. :wink:
If you redefine __non_webpack_require__()
to the one on the readme, you shouldn't need setting the ContentLibrary
type for libContent
explicitly since the return type always is correct.
And you can get type competion on the string
parameter for __non_webpack_require__()
.
Hi,
If I use this library to validate Content that is a media-type content it looks like it doesn't except
.media.attachment
as something to exist withincontent.data
. But if you upload an SVG to Content Studio, it stores some data here. Today we bypass this with a @ts-ignore.Is this expected? Maybe I'm using it wrong. I'm using 1.4.0 of this lib, but used 0.0.74 before and recently upgrading didn't solve the problem.