44
55use Dotcms \PhpSdk \Utils \DotCmsHelper ;
66use Dotcms \PhpSdk \Model \Content \Contentlet ;
7+ use Dotcms \PhpSdk \Model \Layout \ContainerRef ;
78
89class DotCmsHelpers
910{
@@ -42,4 +43,54 @@ public function generateHtmlBasedOnProperty(Contentlet $content)
4243 // Fall back to the SDK simple HTML renderer
4344 return DotCmsHelper::simpleContentHtml ($ content ->jsonSerialize ());
4445 }
46+
47+ /**
48+ * Render a complete container with empty state support
49+ *
50+ * @param ContainerRef $containerRef Container reference
51+ * @param array $contentlets Array of contentlets
52+ * @param string|null $mode Current mode (EDIT_MODE for UVE)
53+ * @param callable|null $contentRenderer Custom content renderer
54+ * @return string Rendered container HTML
55+ */
56+ public function renderContainer (
57+ ContainerRef $ containerRef ,
58+ array $ contentlets ,
59+ ?string $ mode = null ,
60+ ?callable $ contentRenderer = null
61+ ): string {
62+ // If no custom renderer provided, use the existing Laravel content rendering logic
63+ if ($ contentRenderer === null ) {
64+ $ contentRenderer = function (Contentlet $ content ) {
65+ $ contentType = $ content ->contentType ;
66+ if ($ contentType ) {
67+ $ viewPath = 'dotcms.content-types. ' . strtolower ($ contentType );
68+ if (view ()->exists ($ viewPath )) {
69+ return view ($ viewPath , ['content ' => $ content ])->render ();
70+ }
71+ }
72+ // Fall back to the SDK simple HTML renderer
73+ return DotCmsHelper::simpleContentHtml ($ content ->jsonSerialize ());
74+ };
75+ }
76+
77+ return DotCmsHelper::renderContainer ($ containerRef , $ contentlets , $ mode , $ contentRenderer );
78+ }
79+
80+
81+
82+ /**
83+ * Rewrite container identifier for dynamic host support
84+ *
85+ * @param ContainerRef $containerRef Container reference to modify
86+ * @param string $newHost New host to use
87+ * @return ContainerRef Modified container reference
88+ */
89+ public function rewriteContainerIdentifier (ContainerRef $ containerRef , string $ newHost ): ContainerRef
90+ {
91+ if (isset ($ containerRef ->identifier )) {
92+ $ containerRef ->identifier = str_replace ('//demo.dotcms.com/ ' , "// $ newHost/ " , $ containerRef ->identifier );
93+ }
94+ return $ containerRef ;
95+ }
4596}
0 commit comments