Re: apply decorator base on url pattern or parameter?
Aaron Jackson <[email protected]> Wed, 29 Jun 2005 09:00:44 -0600
| Newsgroups | gmane.comp.web.sitemesh.general,gmane.comp.lang.pnuts.user |
|---|---|
| Message-ID | <[email protected]> |
I have used two different techniques to accomplish this in the past. Both techniques use a single decorator to handle the primary layout. In your case the common header and footer. The pages being decorated then dictate the content that is dynamic. In your case the page menu. *Technique #1 - <decorator:getProperty property="page.contentmenu"/>* The decorator uses the <decorator:getProperty property="page.contentmenu"/>where the page menu is to be included. The page being decorated includes <content tag="contentmenu"> tag with the menu. The decorator will then move the contents of the <content> tag to the location in the decorator page. Example, Decorator: <?xml version='1.0' encoding='utf-8'?> <html xmlns="http://www.w3c.org/1999/xhtml" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:decorator="http://www.opensymphony.com/sitemesh/decorator" xmlns:page="http://www.opensymphony.com/sitemesh/page" xmlns:c="http://java.sun.com/jsp/jstl/core" xml:lang="en" lang="en"> <jsp:output doctype-root-element="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /> <jsp:directive.page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" /> <head> <decorator:head /> </head> <body> <!-- Page menu --> <decorator:getProperty property="page.contentmenu"/> <decorator:body /> </body> </html> Page being decorated: <html> <head> <title>Hello</title> </head> <body> <content tag="contentmenu"> <ul><li>Menu 1</li><li>Menu 2</li><li>Menu 3</li></ul> </content> This is the body. </body> </html> *Technique #2 - JSTL and <c:set> and <c:out>* ** This is similar to the technique #1, but uses the JSTL tags c:set and c:out instead of the decorator:setProperty tag. Example, Decorator: <?xml version='1.0' encoding='utf-8'?> <html xmlns="http://www.w3c.org/1999/xhtml" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:decorator="http://www.opensymphony.com/sitemesh/decorator" xmlns:page="http://www.opensymphony.com/sitemesh/page" xmlns:c="http://java.sun.com/jsp/jstl/core" xml:lang="en" lang="en"> <jsp:output doctype-root-element="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /> <jsp:directive.page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" /> <head> <decorator:head /> </head> <body> <!-- Page menu --> <c:out value="contentMenu" escapeXml="false"/> <decorator:body /> </body> </html> Page being decorated: <html> <head> <title>Hello</title> </head> <body> <c:set value="contentMenu"> <ul><li>Menu 1</li><li>Menu 2</li><li>Menu 3</li></ul> </c:set> This is the body. </body> </html> On 6/28/05, Max Wang <[email protected]> wrote: > > My website need a submenu in main menu! just like : > Main-------- > | > |-----store > | > |------forum > > All page's header and footer is same, but store and forum need different > menu. How can i do it use sitemesh? > My thought is : > I use one decorator decorate all pages, then decorator apply other > decorators base on url pattern or parameter , > But how can i do it??? > > --------------------------------------------------------------------- > Posted via Jive Forums > > http://forums.opensymphony.com/thread.jspa?threadID=3740&messageID=9400#9400 > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > -- Aaron Jackson [email protected] // __o // '\<, // (_)/ (_) car--; "Everything should be as simple as it is, but not simpler." -Albert Einstein