HTML Upload like how Hippo used to work?

Hippo used to have a file upload for the CMS that you could upload an HTML file with whatever HTML content (and even references) and you could then inject that into your page, without it stripping that out. How do you do this in the current platform?

The CMS is functionally the same, only with improvements from Hippo days. You can still upload asset files from the Content Perspective.

Do you recall which version of Hippo you last used with this feature? Are you sure that the functionality you are referring to was not provided by a plugin?

We used this. Where would we upload this now? Is it a particular content-type?
@ParametersInfo(type = CustomHtmlComponentInfo.class)
public class CustomHtmlComponent extends BaseComponent {
private static final Logger LOG = LoggerFactory.getLogger(CustomHtmlComponent.class);

public void doBeforeRender(final HstRequest request, final HstResponse response) {

final CustomHtmlComponentInfo paramsInfo = getComponentParametersInfo(request);
final String docParam = paramsInfo.getDocument();
CustomHtml document;

document = getDocumentByPath(request, docParam, CustomHtml.class);

if (document == null) {
  final HstRequestContext requestContext = request.getRequestContext();
  document = requestContext.getContentBean(CustomHtml.class);

}

List<HippoResourceBean> listOfResources = document.getHtml();
for (HippoResourceBean htmldoc : listOfResources) {
  if (!htmldoc.isBlank()) {

    try {
      request.setAttribute(REQUEST_ATTR_PARAM_INFO, paramsInfo);

      request.setAttribute(REQUEST_ATTR_DOCUMENT, getRawHtml(htmldoc));
      request.setAttribute("hippoDocument", document);
    } catch (RepositoryException | IOException e) {
      LOG.error("Error setting raw html resource to document", e.getMessage());
      e.printStackTrace();
    }
  }

}

}

private String getRawHtml(HippoResourceBean hippoResourceBean)
throws ValueFormatException, PathNotFoundException, RepositoryException, IOException {
Node node = hippoResourceBean.getNode();
Binary binary = node.getProperty(“jcr:data”).getBinary();
String rawData = binaryToString(binary, hippoResourceBean);
return rawData;
}

private String binaryToString(Binary binary, HippoResourceBean hippoResourceBean)
throws IOException, RepositoryException {
StringWriter writer = new StringWriter();
IOUtils.copy(binary.getStream(), writer, hippoResourceBean.getProperty(“jcr:encoding”));
return writer.toString().trim();
}

Oh, forgot to add the base class:

@FieldGroup(value = {“document”, “id”})
public interface CustomHtmlComponentInfo extends BaseComponentInfo {

@Parameter(name = “document”, required = true, displayName = “HTML Content Document”)
@JcrPath(isRelative = true, pickerConfiguration = “cms-pickers/documents-only”,
pickerInitialPath = “customhtml”, pickerRemembersLastVisited = true,
pickerSelectableNodeTypes = CustomHtml.NODE_TYPE)
String getDocument();

@Parameter(name = “bodyClass”, required = false, displayName = “Body class”)
String getBodyClass();

Hi,

the functionality you describe would always have been a project specific implementation. From what you posted there would be a document type with a binary field where you upload the data. This is then put on the request by a component, and presumably there is a template that injects this into a page.

If you are on the PaaS platform or on premise then you need to implement this yourselves. On SaaS you could still put html into a document (a text field perhaps) and then have that retrieved by your frontend.

We did end up using a simple text box to add the content in a way that didn’t get “cleaned” by the WYSIWYG and it worked to accept that on the front-end. As this is unsafe, by default our front-end will not execute scripts. However, we built an override option for enabling that in the component as well for those rare exception cases. Thanks.

You might consider attaching a validator to that field.