I am creating a block view wich has to render either a iframe video or a video mp4 stored in media.
I have achieved the first case, the iframe, but for a mp4 i get the mediaKey but dont know how to get the other properties, like the name and the url.
I would like to know how to do it and please point me to the docs section where it explains how to query data inside block views or property editors, i cant find it!
This is my code:
import { html } from “@umbraco-cms/backoffice/external/lit”;
import { customElement } from “@umbraco-cms/backoffice/external/lit”;
import { BaseBlockView } from “../shared/base-block.js”;
import { sharedStyles } from “../shared/styles.js”;
@customElement(“video-block-view”)
export class VideoBlockView extends BaseBlockView {
In v17 you need to resolve the mediaKey through the Media repositories. Inside a block view you don’t get the full media item automatically — only the key — so you must fetch it.
Add these imports
import { state } from '@umbraco-cms/backoffice/external/lit';
import { UmbRepositoryItemsManager } from '@umbraco-cms/backoffice/repository';
import {
UmbMediaUrlRepository,
UMB_MEDIA_ITEM_REPOSITORY_ALIAS,
type UmbMediaItemModel
} from '@umbraco-cms/backoffice/media';
Add these properties to your class
#mediaItemManager = new UmbRepositoryItemsManager(
this,
UMB_MEDIA_ITEM_REPOSITORY_ALIAS
);
#mediaUrlRepository = new UmbMediaUrlRepository(this);
@state()
private _mediaData?: UmbMediaItemModel;
@state()
private _mediaUrl?: string;
That worked! thank you!
And to query content for instance from a content picker how could i get the content key and query like you did on the media section?
Are there any examples of this in the documentation?