So everything you needed to do for xdv to get it to go HTML5 is now no longer necessary. I thought I’d have to use a registry.xml to be able to have a HTML5 doctype, which wouldn’t help much with the zip deployment of themes. But yesterday I saw it set in a manifest.cfg on the ploneconf (2011).
An example HTML5 manifest.cfg file:
[theme]
title = My Theme
description = Description of your theme
rules = /++theme++my.theme/directory/rules.xml
prefix = /++theme++my.theme/directory
doctype = <!DOCTYPE html>
Another nifty little trick I’ve seen yesterday was the use of xsl:apply-templates and css:select. For instance if you want to do something silly with your breadcrumb.
xsl:if
This tests if the “breadcrumb-1″ id is available (when you have more than just home)
append
Select the div with the breadcrumb id
xsl:for-each Loops through all the children of spans, directly under portal-breadcrumbs, that do not have the “breadcrumbs-you-are-here” id.
xsl:choose
For when you have multiple scenarios. In this case sort of if else, but you could have lots of different cases.
xsl:when
First scenario, in this case selecting the breadcrumb separator and changing it.
span
Yes, you can add html structure like this.
xsl:otherwise
If none of the above scenario’s match, then do this.
xsl:apply-templates
Put the content you select into the theme side. In case of a for-each the selection is relative to the for each select.
The xsl:apply-templates bit I used to do by useing xsl:copy-of, which put the content there, but takes it out of the xdv loop. The xsl:apply-templates way leaves it in.
The greatest thing to me about XDV is that you can leave Plone as it is and alter nearly everything about it. Mostly xdv will suffice, but when necessary you can even grab for xsl. You’re not even doctype bound. I’ve been working on an XDV theme based on HTML5 boilerplate.
Compared to my previous post on moving from xhtml 1.0 transitional to strict, this was a bit less of a picknick. More like a night in the wild having to catch and collect your own food. I ran into some major hurdles. Here is how I crossed them.
First off, get HTML5 Boilerplate and create a basic theme. Then start with the rules file, starting off with changing the doctype according to Denys his method.
<!-- Set output to HTML5 -->
<xsl:output doctype-public="html" doctype-system="" />
Mostly I start with filling the head, working my way down through the HTML. Now after the doctype is where the trouble started. Wanting to use most of the plone metatags, but have the html5 charset and the boilerplate IE edge statement proved more of a problem than I anticipated. Though mostly because I needed to refresh my xpath expressions. I went through a few XSL attempts after realizing i could just do it with regular XDV.
<!-- Pull in Plone Meta -->
<!-- Exclude HTML5 specific meta defined in Boilerplate -->
<xdv:after
theme="/html/head/meta[last()]"
content="/html/head/meta[
not(@content='IE=edge' or
@content='text/html; charset=utf-8')]" />
Next up, were the script tags. The XSL transform caused them to self close, rendering them invalid (Gotta love that validator). They always need a closing tag. I did not fill any scripts, because I wanted them all to be static resources. This was not a problem when turning xhtml to strict so I was a bit baffled. Turns out that XSLT works different when you have an xhtml doctype. It turns out all empty tags were automatically self closed. The solution for this was adding comments to all the non void tags (tags that are not allowed to self close) or part of the solution at least. This issue had a tail. Beware that script tags need javascript comments instead of regular html ones to be valid.
All the issues seemed to be solved, so I started filling content until I was ready to run it through a validator again. Once again I ran into self closed tags that were not allowed to be closed. This time it was span’s and div’s from the content side. Looking through posts and forums I ran into the problem, but not really a feasible solution. After a lot of part solutions and even a post from Laurence Row, I ended up with the following XSL. It seems to work, but it has not been greatly tested yet.
Update: Found a way to shorten the code. copy-of can strip the whole for-each blocks and the xsl:comment gets stripped, but leaves the closing tag in place. This removes the need for special casing the script element.
Let me know if you use it. Any changes I’ll post here.
Update 2: For Diazo all this is no longer necessary
With Plone’s new theming mechanism it is a breeze to conform to a strict doctype necessary for the Dutch Web-guidelines (Webrichtlijnen Overheid). This post is actually long overdue since I’ve done this at least half a year ago, but still, better late then never.
I’ll start of giving the rules.xml used to do it and then I’ll explain the parts of it.
<?xml version="1.0" encoding="UTF-8"?>
<xdv:rules
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xdv="http://namespaces.plone.org/xdv"
xmlns:css="http://namespaces.plone.org/xdv+css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Strict will need rules to fix plone Transitional differences -->
<xsl:output
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
method="xhtml" />
<!-- Remove whitespace because of line ends breaking validation. -->
<xsl:strip-space elements="ul ol dl" /> <!-- Remove name attribute from forms -->
<xdv:drop content="//form/attribute::name" />
</xdv:rules>
As you can see, I start of namespacing the different dialects in the rule file. A lot of the online tutorials don’t show it this way. They generally have the xdv namespace as the default. I started of like that but it caused validation errors because the default namespace got the namespace added to some of the tags. Namespacing everything explicitly solved this.
<xdv:rules
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xdv="http://namespaces.plone.org/xdv"
xmlns:css="http://namespaces.plone.org/xdv+css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
The next step is to change the output doctype. I’ve focussed on getting the code to comply to xhtml 1.0 strict, but in theory it is also possible to turn it into html4.01 stict. For plone it’s easier to go for xhtml since it’ s already xhtml 1.0 transitional.
<xsl:output
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
method="xhtml" /> <!-- For html 4.01 you would use this code, the other rules on this page won't work to help validate that though, you'd have to find out for yourself what works. -->
<!--xsl:output
doctype-public="-//W3C//DTD HTML 4.01//EN"
doctype-system="http://www.w3.org/TR/html4/strict.dtd"/-->
Now our doctype for the XDV themed part of the site is shtml 1.0 strict. The content source is still transitional though. For the content to be valid we also need to make some changes to it. First off, the xsl transform caused whitespace characters to show up in places they were not allowed to show up. The issue was with character &13;.
I’ve solved this by selectively stripping whitespace. For now it is just stripped between list items. This is however a growing list. So far I haven’t run in to the problem anymore, but if I will I’ll update the items that need their whitespace stripped. Another option would be to strip all whitespace, but with this you would be risking stripping significant whitespace. <!-- Remove whitespace because of line ends breaking validation.
This rule will only remove whitespace between li, dt and dd elements.
<xsl:strip-space elements="ul ol dl" />
The rules below will remove them all, which could cause trouble if
there is significant whitespace without text between two elements.
<xsl:strip-space elements="*" />
<xsl:preserve-space elements="pre" /> -->
<xsl:strip-space elements="ul ol dl" />
Another validation error was caused by the name attribute on forms. This was an easy strip. Most Plone forms already have an id. If you’re in a situation this is not the case you could decide, instead of dropping it, to set from name to id.
<!-- Remove name attribute from forms -->
<xdv:drop content="//form/attribute::name" /></xdv:rules>
The installation of python2.4 on Ubuntu 10.04 had me pulling the hair from my head. I needed to deploy a Plone project using Fabric and buildout-source-release and python2.4, but the latter has been dropped for Ubuntu 10.04. Through dirty hacks it was possible to release, but now I’ve got the propper solution.
For a customer I needed to have an old school custom Plone template not to be cashed. The site was put behind varnish and just adding “no-cache” headers did not work.
The solution was creating an extra rule in the “Cache Configuration Tool” (http://yourplonecms.com/portal_cache_settings/with-caching-proxy/rules), which allows for quite a lot of customization.
To the top of the existing rule set, add a copy of the plone-templates. In the rule under “Templates” add your template id and for the “Header Set for …” set both dropdowns to “Do not cache”. This should do the trick, at least it did for me.
This book has proven to be a great read. It is: easily written, focussed on web designers, has great regard for web standard and builds up nicely by showing all the steps and then sticking them together in a fictional case.
Based on semantic HTML and CSS the book shows you how to enhance the user experience with JavaScript without adding relevant content. As a web developer with python experiance but less knowledge of JavaScript this book quickly clarifies how to do things the right way.
Starting of with a brief history of JavaScript, followed by basic syntax explanation. It then gives an explanation of the DOM. Through a set of carefully explained examples of javaScript enhancements, like for example: an image gallery and folding of content based on a subnavigation, the book leads to putting it all together in a final example case.
After reading the book it will be easier to recognise the good JavaScript from the bad. The frequently used “copy/paste” code, becomes higher quality (if you take the trouble to read the code before “copy/pasting”). You also want to start writing scripts yourself because after the book JavaScript looks easy and fun.
While updating a plone 3.1.7 instance to 3.2.1 I all of the sudden had the following import error:
ImportError: No module named ImplPython
Searching the net I only found irrelevant solutions to my situation. I had an other plone 3.2.1 instance that used to work, so I checked if it would still run and it did. Creating a test instance of that buildout, once again didn’t work. Running a div between the two instance files showed 3 differences.
zope.component-3.5.1 was now zope.component-3.6.0
and two missing packages
zope.deferredimport
zope.deprecation
(both dependencies of zope.component-3.5.1)
Version pinning zope.component-3.5.1 in the buildout solved the import error.
Our office network has horrible download speeds, it is more efficient to zip a file before copying it. (No longer slow but still nice to not forget this)
For a generic plone 3 portlet with a template portlet.pt and a module named portlet.py, this is what you need to do to subclass it. I tend to create a portlets folder in my porducts, which you have to register in the same way as the browser folder from your theme is registered. Don’t forget the __init__.py and a configure.zcml!
Copy portlet.pt template from the source egg into your theme’s portlets/ directory. Don’t copy portlet.py, but instead create your own portlet.py. It needs only the following measly five lines of code:
from source.egg.portlet import Renderer
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
class MyPortletRenderer(Renderer):
render = ViewPageTemplateFile('portlet.pt')
In portlets/configure.zcml put the following lines:
If, like in this example, the template in the renderer is called render (so render = ViewPageTemplateFile(‘portlet.pt’)) and not index or _template or something the like, you just use the template instead of creating a class for it in a special portlet.py. The subclassing also works with multiple templates or differently named ones.
Setting up a host for a server in the ssh config and creating an ssh tunnel.
For this your would have to have access to a server. Open your ssh configuration in a text editor.
gedit ~/.ssh/config
Add the server specifications.
Host host
HostName path.to.server.com
User username
Create an ssh tunnel.
ssh host -L8080:127.0.0.1:8080
Now you can reach host as if it were 127.0.0.1 (localhost). “-L8080″ stands for your local host, “127.0.0.1:8080″ stands for what you are on the other side of the tunnel.