Hello, Is it possible to use a variable value for metal:use-macro. I have a site that is using page templates and I have implemented a scheme that can have different layouts. Each layout may have different skins. Layouts allow me to have multiple site designs with the same basic elements and the same content, but I can position elements such as the logo or menus in different places. Layouts also allow me to use different methods for defining a layout, i.e. tables for older browsers and layers for newer browsers. Each layer may have different skins. A skin defines which graphical elements and css file to use with a certain layout. Ideally the layout and the skin for the layout would be changeable by me or the visitor to the site. The functionality I want to have is to support older browsers with a basic layout and support new browsers with a more advanced layout, or having a layout geared to those with bad eyesight, or allowing those with logins to choose their preferred layout and skin, or to change the layout or skin of the entire site for basic design updates by changing a variable. To start off with I just have two properties on the root folder, layout and skin. I have two scripts, get_skin and get_layout. Calling each returns the skin or layout using the variables in the layout and skin properties. In the future I may also check a session variable or perhaps a querystring parameter for these values. Each page template in the site currently begins with a metal:use statement and so far the value is a static string. What I want to accomplish is to insert a variable for the value. Everything I have tried thus far has failed to work. Can you use statements in the metal directives that you can use in the tal directives? Does metal except string: and python: combinations and how could I best insert a dynamic value for this directive given a layout variable. Different pages use different templates within the layout. I have a frontpage template, sub_page template and sub_page_index template. <html metal:use-macro="container/layouts/default/frontpage/macros/standard"> <div metal:fill-slot="content"></div> </html> The value for metal shown above consists of the layout variable portion 'container/layouts/default' and the static layout template portion '/frontpage/macros/standard'. How could I set the value of the metal:use-macro directive to a string value containing the layout variable and a static string portion as show above? Thanks, David
"David Sumner" <david@dragontail.com> a écrit dans le message de news:000201c3cef2$4ac27010$0300000a@nomad... Hello, Thanks, David
[ didn't copy the source cause you posted in HTML :-( ] metal:use-macro requires a TALES expression. You could use such a thing in your publishing template... <html metal:use-macro="python: here.macroChooser(someCriteria)"> ... </html> Let's assume that all your macros "macro1" and "macro2" are in a template called "all_macros", the script "macroChooser" could look like this... ##parameters=someCriteria if myCondition(someCriteria): macroname = 'macro1' else: macroname = 'macro2' return context.all_macros.macros[macroname] Untested but this should work... Of course, you could have your own logic to return the appropriate macro in "macroChooser" (playing with several macro collections templates...) HTH -- Gilles
David Sumner wrote:
Hello, [...]
Ideally the layout and the skin for the layout would be changeable by me or the visitor to the site. The functionality I want to have is to support older browsers with a basic layout and support new browsers with a more advanced layout, or having a layout geared to those with bad eyesight, or allowing those with logins to choose their preferred layout and skin, or to change the layout or skin of the entire site for basic design updates by changing a variable.
Btw. this is all possible with a clean HTML structure and CSS. No need for different macros here. Really. Sure, it can be done, but the pure CSS (you can also choose different CSS definitions) approach will give you better performance - both in authoring and viewing. Regards Tino Wildenhain
participants (3)
-
David Sumner -
Gilles Lenfant -
Tino Wildenhain