Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add CmsBlockHtml and CmsElementHtml #1727

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fluffy-ghosts-strive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@shopware/cms-base-layer": minor
---

Added CmsBlockHtml to render html blocks.
Added CmsElementHtml to render html element.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Render a HTML section
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script setup lang="ts">
import type { CmsBlockHtml } from "@shopware/composables";

defineProps<{
content: CmsBlockHtml;
}>();
</script>

<template>
<div>
<CmsGenericElement
v-for="slot in content.slots"
:key="slot.versionId"
:content="slot"
/>
</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script setup lang="ts">
import type { CmsElementHtml } from "@shopware/composables";

import { getCmsLayoutConfiguration } from "@shopware/helpers";
import { h } from "vue";

const props = defineProps<{
content: CmsElementHtml;
}>();

const { cssClasses, layoutStyles } = getCmsLayoutConfiguration(props.content);

const HtmlComponent = () => {
return h("div", {
class: cssClasses,
style: layoutStyles,
innerHTML: props.content.data.content || "",
});
};
</script>

<template>
<HtmlComponent />
</template>
1 change: 1 addition & 0 deletions packages/composables/src/types/cmsBlockTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ export type CmsBlockProductDescriptionReviews = BlockType<"content">;
export type CmsBlockCrossSelling = BlockType<"content">;

export type CmsBlockForm = BlockType<"content">;
export type CmsBlockHtml = BlockType<"content">;
9 changes: 9 additions & 0 deletions packages/composables/src/types/cmsElementTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ export type CmsElementText = Schemas["CmsSlot"] & {
};
};

// HTML
export type CmsElementHtml = Schemas["CmsSlot"] & {
type: "html";
data: {
content: string;
apiAlias: "cms_html";
};
};

// Image

type ImageElementConfig = {
Expand Down
Loading