Diazo add unwanted html header into json response - plone

I have a blank Plone 4.1 site with only collective.quickupload installed. The upload portlet worked fine until I install plone.app.theming and apply my theme. The files were still uploaded, but the web client got "Failed" status.
Inspecting the ajax response from server I found that they were wrapped by html header.
The old response (before install diazo & apply my theme) was simply
{"success":true}
The new response (after install diazo and apply my theme) was being wrapped by a html tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><body><p>{"success":true}</p></body></html>
I've pasted my rule.xml file here (nothing special, there is only one rule conditioned by css:if-content="#visual-portal-wrapper"): http://pastebin.com/SaK13Fni
What should I do to work around this ?
Thanks

To avoid this behavior you have to add an exception in your rules.xml that specify to not apply your theme to your specific view , like this:
<notheme if-path="myjson_view"/>
edit:
I've tried with one of my diazo themes and a json view and I didn't have your issue. So I think the problem is either in your rules.xml or in your json view. You should try one of these two way:
change your rules.xml this way:
<rules
xmlns="http://namespaces.plone.org/diazo"
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Prevent theme usage in zmi-->
<rules css:if-content="#visual-portal-wrapper">
<theme href="index.html" />
</rules>
have you already specified the "Content-type" of the output in
your json view? Like this:
self.request.response.setHeader("Content-type","application/json")
return json_data
If not, that's probably the problem.

Watch out for using Chrome inspector... it adds the html head and pre tags around your json when you inspect it...it's not actually there if you look at view:source of the page (old school)...

Related

Returning a page template without diazo

Running: Plone 5.0.0 with Diazo.
How does one permanently bypass the diazo theme applying in BrowserView templates? (Not with the diazo.off=1)
Example:
I have a diazo theme. I have a template that I'm returning via a BrowserView's ViewPageTemplateFile:
class ExhibitView(BrowserView):
template = ViewPageTemplateFile("exhibit.pt")
def __call__(self):
return self.template()
The exhibit.pt file is as follows:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
i18n:domain="plone"
lang="en">
<body>
Is it just this text?
</body>
</html>
I removed the plone master template, it is still applying the diazo rules. I just want it to return a barebone template, unthemed by diazo. We used to be able to do that before Diazo as I shown above.
Also making a Diazo rule to skip this is out of the question because it has to be installed in many places, I don't want to apply rules to everyone's site themes to make this work. That is hacky.
Thanks in advance!
According to this line:
https://github.com/plone/plone.app.theming/blob/5ba9447150776f7edbfd73b528b9b62f31dd14b5/src/plone/app/theming/policy.py#L79
If you have an header called 'X-Theme-Disabled' the transform is not applied. Two lines later you see the condition that is checking for "diazo.off".
So you should modify your __call__ method in a way that it sets the header before returning the template.
Something line this:
def __call__(self):
self.request.response.setHeader('X-Theme-Disabled', '1')
return self.template()
The control panel is doing the same:
https://github.com/plone/plone.app.theming/blob/fbbdc3bfdbccf2315cef069fe827fea863feb1c8/src/plone/app/theming/browser/controlpanel.py#L72
Caveat: I did not tested this :)

How to change Doctype and Content-Type of a Meteor-App

I need to change the doctype and the content-type of a meteor-app to get CE-HTML-related things working.
Meteor works fine on CE-HTML-devices like Set-Top-Boxes. But without setting the correct doctype and content-type of the main request, some CE-HTML-based extensions won't work properly.
Thx,
Joerg
I'm assuming you mean you want to add these to the top of your app.html:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ce-html-1.0-transitional.dtd">
What you want to do is find
~/.meteor/tools/latest/tools/app.html.in
and edit it to add your doctype and content-type.
Note: this is a hack. It will change the doctype and content type for all of your Meteor apps. Whenever you launch your Meteor app or bundle it, this template is used.

Tridion Rich Text Field DWT   output to "?"

Rich text field value <div> </div>
output <div>?</div>
DWT:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
##Component.Fields.Text##
</html>
what did i miss?
thanks
I can't try it out now due to lack of time, but a few things come to mind:
What's the encoding set on your publication target?
Do you get the same result in Template Builder and Preview?
If you open the published file with a text editor like Notepad++, what does it show?
EDIT
In preview I get this:
<div> </div>
After publishing I get the same as you:
<div>?</div>
So I changed my publication target to use "Unicode (UTF-8)" instead of "System Default", and now when I publish I get this:
<div> </div>
I then referred to Elena's excellent 7 clues to deal with encoding, and figured out I was missing this on my web.config:
<globalization fileEncoding="UTF-8" requestEncoding="UTF-8" responseEncoding="UTF-8"/>
This still didn't do it, it was still loading this weird character in between the tags. This last clue was because the encoding was not being applied to pages with the ".html" extension. Renamed my page template to have a .aspx extension, published, pressed F5 and magic, my div now shows:
<div> </div>
EDIT 2 If you want to use the .html extension, just add this to your page's <head>:
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">

Correct content type for html use?

I was using XHTML on my website but that completely destroyed jQuery and its plugins.
Therefore, I want to go back to html 4. I am defining some custom attributes for my html, like so:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd" [
<!ATTLIST mytag myattribute CDATA #IMPLIED>
]>
This seems to be valid html for, but when I pass such a page from my server with a content type of text/html, my browser displays ']>' - it can't parse the doctype properly.
Is there a different content type I should be using?
From A List Apart
If you run such a file through the W3C validator, you find that it
validates wonderfully well. If you download the sample files for this
article and validate file internal.html, you can see this for
yourself. Unfortunately, when you display the file in a browser, the
]> shows up on the screen. There’s no way around this bug, so this
approach is right out.
So this basically isnt going to work. To get it to work you need to copy the DTD you want the server/local machine, edit it appropriately and put it in a publically accessible place. See the article for more detail.
As far as jQuery is concerned, it should work fine if you quit trying to customize the DTD in the fashion that you are. Im not sure about using a custom DTD as I have never done it, but just adding the attributes to the elements and not defining them in the DTD shouldnt cause a problem with jq. Granted the document wont validate, but validation is just a tool and not overly important in the grand scheme of things.

Is it possible to remove base and Content-Type + alter HTML attributes in Diazo?

I am trying to make a HTML5/CSS3 theme with Diazo from a Plone site, using plone.app.theming 1.0b8. It is working like a charm in the BODY part. But the HTML tag and HEAD part are more difficult. To me at least :)
I have tried to:
remove xmlns and xml:lang attributes in the HTML tag
<drop attributes="xmlns xml:lang" theme="/html/" />
remove base tag
<drop theme="/html/head/base/" />
remove meta tag where http-equiv="Content-Type"
<drop theme="/html/head/meta[#http-equiv='Content-Type']" />
I am wondering if plone.app.theming or Diazo is forcing these things into the output, or if it's my xpath which is buggy? I have searched around but found no answers.
BR
Your xpaths probably should not end with a trailing '/', though I don't think this is the problem here.
It won't be possible to remove the xmlns attribute as that is added by XMLSerializer in XHTML mode (at least under common circumstances). You could set an HTML serialization instead with <xsl:output method="html"/> inside your root rules tag.
In XHTML mode, the XMLSerializer will add an xml:lang to match the lang attribute. Again, try setting the html serialization.
Normally the base tag gets copied from the content into the theme - there ought to be no reason to have a base tag in a theme html file. If you don't copy it over, it won't end up in the output. However it is advisable to always include a base tag in output from Zope as the same page will be rendered at both http://localhost/some_url and http://localhost/some_url/, which will lead to differences with any relative urls.
The content-type header is added by libxslt is unconditionally added by libxslt and is impossible to suppress.

Resources