How can I get the result of a template without HTML-Tags?

How can I get the result of a template without HTML-Tags?

When I use the following view SituationView with a plain text template I get a result with HTML-Tags.

class SituationView(ViewMixinForTemplates, BrowserView):
    index = ViewPageTemplateFile("")

    # setting the content_type to 'text/plain' returns html-tags too.
    # index = ViewPageTemplateFile("", content_type='text/plain')
some text
$ curl "http://localhost:8081/Plone/de/situation/@@situation-view"

<!DOCTYPE html>
<html xmlns=""><body><p>some text

That might be a Diazo thingy.
Could you try to disable theming for the view by setting the X-Theme-Disabled header?

@jaroel: Thanks. This is exactly what I was searching for.

Reading the source code of I found two important things:

  • the value of the header X-Theme-Disabled is irrelevant for disabling the theme

  • theming can also be disabled using the request parameter In my example above: http://localhost:8081/Plone/de/situation/@@situation-view?

The source code for

    def isThemeEnabled(self, settings=None):
        """Whether theming is enabled."""


        # Disable theming if the response sets a header
        if self.request.response.getHeader('X-Theme-Disabled'):
            return False
        # Check for request parameter
        true_vals = ('1', 'y', 'yes', 't', 'true')
        if (debug_mode and self.request.get(
                '', '').lower() in true_vals):
            return False

The following is also a solution:

class SituationView(ViewMixinForTemplates, BrowserView):
    index = ViewPageTemplateFile("")
    def __call__(self, *args, **kw):
        #self.request.response.setHeader('X-Theme-Disabled', 'True')
        self.request.response.setHeader('Content-Type', 'text/plain')
        return super().__call__(*args, **kw)

But I'm still wondering why the following doesn't set the header Content-Type:

index = ViewPageTemplateFile("", content_type='text/plain')

You can also set the headers in your page template.

Here we're downloading an Excel sheet from Plone:

download_xlsx_template = ViewPageTemplateFile('templates/')
[ do something ]
return self.download_xlsx_template(
                    filename = filename,
                    data     =

<html xmlns="" xml:lang="en"
      tal:define="filename options/filename;
                       dummy python:context.REQUEST.response.setHeader('Cache-Control', 'no-cache');
                       dummy python:context.REQUEST.response.setHeader('Pragma', 'no-cache');
                       dummy python:context.REQUEST.response.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
                       dummy python:context.REQUEST.response.setHeader('Content-Disposition', 'attachment;; filename=' + filename  );
                       dummy python:context.REQUEST.response.write(options['data'])"

@mtrebron Thanks. This is a really good idea. No need to mess with the view.

Actually you only need:

<tal:_ tal:define="_ python:context.REQUEST.response.setHeader('Content-Type', 'text/plain')" />

Or simply:

<?python context.REQUEST.response.setHeader('Content-Type', 'text/plain') ?>
1 Like