I use Diazo to deploy the static html-file 'ticker.html' on a certain url. That page uses nothing at all from the content.
This is the rules.xml:
<rules xmlns="http://namespaces.plone.org/diazo"
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<rules if-path="/Plone/ticker/ /ticker/">
<theme href="ticker.html" />
</rules>
<rules css:if-content="#visual-portal-wrapper" if-not-path="/Plone/ticker/ /ticker/">
<theme href="index.html" />
The rest of the theme...
</rules>
</rules>
It works fine and the html is correct but the return-code of http://localhost:8080/Plone/ticker is 404. Only if I create some dummy content in Plone at this location I get a 200. The returned is also slightly changed: When there is a dummy content Diazo adds a base-tag to the header:
<base href="http://localhost:8080/Plone/ticker/" />
How can I tell Diazo to completely ignore the content and return a 200 even when there is no dummy-content?
In case you are wondering: I use Diazo for this because plone.app.themeing allows to modify the static page through the web.
The plone.app.theming transformation is the last step in the delivery pipeline. The content has already been summoned from Plone so that it can be combined with the theme. So, it's not the appropriate place to do this.
Instead, do this with the rewrite rules of your reverse proxy. Have the proxy fetch your ticker whenever it receives a request for the target URL. You'll also save a lot of CPU cycles in the process, since you'll avoid the whole trip through Zope/Plone's machinery.
I had a similar usecase where i want to server some js-partials through Zope to AngularJS. They are text/html so they got transformed through plone.app.theming. After a deep look into plone.app.theming i overloaded the ThemeTranform adapter with a subclassed one in a new file transforms.py as shown below:
# -*- coding: utf-8 -*-
from plone.app.theming import transform
from your.theme.interfaces import IYourThemeLayer
from zope.component import adapter
from zope.interface import Interface
#adapter(Interface, IYourThemeLayer
class ThemeTransform(transform.ThemeTransform):
def parseTree(self, result):
# Prevent diazo from adding doctype and html head to every
# html file. Exclude all partial resources from theme transforms
if '/++resource++your.theme.js-partials/' in self.request.getURL():
return None
return super(ThemeTransform, self).parseTree(result)
... and register in zcml to the same name as the default ThemeTransform adapter using:
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="your.theme">
<!-- Override plone.app.theming adapter -->
<adapter
name="plone.app.theming.transform"
factory=".transform.ThemeTransform"
zcml:condition="installed plone.app.theming"
/>
</configure>
May be related to this issue: https://dev.plone.org/ticket/13139
Related
I need a solution that meets following requirements:
use a diazo theme based on unstyled(!), Theme base (i.e. "Plone Default") with the URL diazotheme.domain.com
use "Sunburst Theme" (or any other Plone Theme) with the URL "sunburst.domain.com"
It seems that diazo not only uses the Base Theme for the diazo theme but also for the "Unthemed host names". Setting the Base Theme in diazo's "##theming-controlpanel" actually changes the Default skin of the Site.
I've posted a solution using diazo in combination with editskinswitcher: https://stackoverflow.com/a/23130398/1659599. I'd like to know whether this is possible without using editskinswitcher.
Take a look at the collective.behavior.localdiazo package.
You can see it in action in http://www.cfa.org.br/rba site, which has a different theme from http://www.cfa.org.br/ main site.
RBA is an instance of Microsite, a Dexterity-based content type defined in sc.microsite.
you'll definitely need a mechanism to activate different skins for the different parts of you site. editskinswitcher is one choice here.
you could also code your own traverser that applies the correct browserlayer and patches the portal_skins tool.
another approach is to allow skin selection in portal_skins and set the skin via a request variable.
the concept is outlined here: https://dev.plone.org/ticket/10311
Do you need to switch plone skin? Or would it be enough to change the diazo theme, using the same (more or less neutral) plone skin?
I use this approach to switch diazo rule set and index.html depending on the path. The two diazo themes uses different resources: images, styles, js, etc., and are very different.
My rules.xml - shortened:
<?xml version="1.0" encoding="UTF-8"?>
<rules
xmlns="http://namespaces.plone.org/diazo"
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xi="http://www.w3.org/2001/XInclude">
<!-- The theme for my "app" -->
<rules if-path="/app_path /site/app_path">
<theme href="index_app.html"/>
<!-- rules for the specific path -->
</rules>
<!-- The default theme, used for standard Plone web pages -->
<theme href="index.html" css:if-content="#visual-portal-wrapper" />
<!-- Rules applying to a standard Plone web page -->
<rules css:if-content="#visual-portal-wrapper">
<!-- rules for the rest of the site -->
</rules>
</rules>
The same should be doable for domains using p.a.theming theme parameters: https://pypi.python.org/pypi/plone.app.theming#theme-parameters
and using "Conditions based on arbitrary parameters" from http://docs.diazo.org/en/latest/advanced.html
(replace the if-path with if="$host = 'domain'")
UNTESTED! :)
I was able to modify the original popup.pt and see changes in my instance, but when I try to override it by copying and renaming to archetypes.referencebrowserwidget.browser.popup.pt in my theme/(add-in) overrides folder I am unable to see my changes.
I overrode the path_bar class viewlet, following this tutorial. I attempted to follow the same logic for overriding popup.pt, but I was unable to get Plone to see the file in my configure.zcml.
configure.zcml:
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="mytheme.theme">
<includeDependencies package="." />
<plone:static
directory="resources"
type="theme"
/>
<genericsetup:registerProfile
name="default"
title="mytheme.theme"
directory="profiles/default"
description="Installs the mytheme.theme package"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
<browser:viewlet
name="plone.path_bar"
manager="plone.app.layout.viewlets.interfaces.IAboveContent"
class=".customizations.PathBarViewlet"
permission="zope2.View"
layer=".interfaces.IMyTheme"
/>
<browser:page
name="login_main_template"
for="*"
permission="zope.Public"
template="login_main_template.pt"
/>
</configure>
While searching for a solution I found this Stackoverflow question - How to customize the popup.pt template from archetypes.referencebrowserwidget?. I added/:
<include package="z3c.jbot" file="meta.zcml" />
<browser:jbot directory="jbot_templates" layer=".browser.interfaces.IThemeSpecific" />
to my configure.zcml and removed the browser:viewlet from my previous attempt but I was still unable to get Plone to see my overview.
Which method do I need to use to override, the class viewlet, the z3c.jbot, or just the standard copy/rename method? I have read thru the Plone documentation multiple times, but still unable to resolve my issue. If I need to post any additional files please let me know.
Thanks in advance.
The z3c.jbot approach usually just works fine.
You have to be sure, that the file you place into to your jbot_templates folder has the right name.
The path to the popup.pt is archetypes/referencebrowserwidget/browser/popup.pt,
So in your case the filename must be archetypes.referencebrowserwidget.browser.popup.pt
Please make sure that your browserlayer .interfaces.IMyTheme is active on your site -> browserlayer.xml
How Can I appends a querystring parameter to each CSS and JavaScript include in the HTML to clear CSS and JavaScript cache.
I have tried
<action
method="addCss"><stylesheet>css/style.css?123</stylesheet></action>
and
<action
method="addItem"><type>skin_css</type><name>css/styles.css?123</name><params/></action>
.
But each time it returns a the base package like
http://www.example.com/skin/frontend/base/default/styles.css?123
not my custom theme directory .
How to solve this ?
This free extension should do what you want - works perfectly for me:
https://github.com/jreinke/magento-suffix-static-files
When you're adding a css file through xml layout updates, the addCss action (which realy just calls the addItem action with the type set to skin_css) is looking for a file path, not a url. While query strings are valid in urls, they aren't in file names. Magento sees that as an invalid parameter, gets confused and falls back to base/default.
I can think of 2 solutions for this. Unfortunately both are kind of hackey.
Move the css file to the base default theme. This works but it depends on fallbacks that might not stay the same in other versions of magento.
instead of directly inserting the css file, create a phtml template file with the html code to insert a css file. Then insert a core/template block with that new template file as its template in the layout xml. I've used this method on the sites i develop for to work around this problem.
Here's what we do:
<reference name="head">
<block type="core/text" name="link.tags">
<action method="setText">
<text>
<![CDATA[<link rel="stylesheet" href="/css/style.css?v=2">]]>
</text>
</action>
</block>
</reference>
Got this idea along with some other useful stuff from 5 Useful Tricks For Your Magento local.xml.
As an alternative, you can always just rename the file from style_v1.css to style_v2.css etc. whenever you make a change -- it has the same effect as changing style.css?v=1 to style.css?v=2.
as a follow up answer to this question i found the following (paid) magento extension which does what you require:
http://www.magentocommerce.com/magento-connect/clear-css-and-javascript-cache.html
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)...
We're trying to develop our Plone 4.1 product using only ZTK (Zope 3) views and hence haven't defined a portal skin. I'm trying to override a view from a different package and in the past have used the layer attribute to do this.
plone.theme allows you to mark the request with a "layer" interface conditional on the currently selected skin. I'd like to mark requests with a "layer" interface if my product is installed, without creating a skin layer. How do I do that?
I have my interface defined already in zcml
<interface
interface=".interfaces.IThemeSpecific"
type="zope.publisher.interfaces.browser.IBrowserSkinType"
name="My Theme"
/>
and declared
from zope.interface import Interface
class IThemeSpecific(Interface):
"""Marker interface for skins part of 'My Theme'
"""
You have to use a browserlayer.
So, if you don't need it for something else, you can remove the zcml interface declaration and keep only the python interface (maybe you can rename it something more specific like IMyPackageLayer). Then add a file browserlayer.xml in your generic setup profile with this:
<?xml version="1.0"?>
<!-- Register the package-specific browser layer, so that it will be activated
when this product is installed. -->
<layers>
<layer name="my.package.browserlayer"
interface="my.package.browser.interfaces.IThemeSpecific" />
</layers>
After that you can use the layer attribute as always:
<browser:page
name="my-view"
for="*"
layer="my.package.browser.interfaces.IThemeSpecific"
/>
Just remember to restart zope and reinstall you product to apply the new genericsetup configuration.
That's all.