2

We are trying to publish a .txt using a code Component by creating a Region and using a custom Page Template for .txt files.

Is there a way to remove the HTML tags that the Region is adding for my Page when I render http://localhost:9080/dev/rb.txt

<%-- <!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%> --%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="dxa" uri="http://www.sdl.com/tridion-dxa"%>
<%@ taglib prefix="xpm" uri="http://www.sdl.com/tridion-xpm"%>

<jsp:useBean id="pageModel" type="com.sdl.webapp.common.api.model.PageModel" scope="request" />
<jsp:useBean id="markup" type="com.sdl.webapp.common.markup.Markup" scope="request" />

<dxa:region name="MainBody" />

This is markup for the Region we are using and below is the Page with code Component.

enter image description here

I want to remove the <html> and the <body> tag from the source to render an raw text file. Could anyone suggest an approach for this?

Follow up question on this : Render the Robots.txt using DXA 1.5 Java

1
  • Sounds like you have found an option to solve the other question then, in that case, please self answer that question. Commented Oct 9, 2017 at 7:53

2 Answers 2

5

As Bart says, DXA in general is designed to generate HTML, but in your case particularly the use of the dxa:region tag causes issues.

You could let the Page View output the content from the "Code Component" directly. For example, to get direct access to the first Entity Model in the "MainBody" Region, you can use this in your Page View: pageModel.getRegions().get("MainBody").getEntities().get(0)

2
  • Thanks a lot Rick! This solution worked : ${pageModel.getRegions().get("MainBody").getEntities().get(0‌​).attribute} Commented Oct 9, 2017 at 18:16
  • @SandeepDeshmukh, please consider accepting this answer if it answered your question. Up votes on helpful answers will also help and encourage community members to answer questions. Commented Oct 9, 2017 at 19:11
4

It is a known issue that when you are trying to use empty Region views, you will get an additional <html>, <head> and <body> tag generated, see https://github.com/sdl/dxa-web-application-java/issues/5

So currently that simply isn't possible, as DXA is basically designed to generate HTML.

The only quick option I could think of in solving this, is to look towards the generation of the configuration JSON files, which are published as a binary variant (which probably should be the answer also to Render the Robots.txt using DXA 1.5 Java) .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.