You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Robert Hailey <ro...@cmediacorp.com> on 2010/03/17 19:18:00 UTC
Modifying the title in a layout component
I'm using 5.1.0.5 and thought I could do something like this...
[Page.tml]
<html t:type="layout" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd
">
<head t:type="header">
<title>My Page Title</title>
</head>
<body t:type="passthru">
<h1>My Page Content</h1>
</body>
</html>
The 'passthru' component was easy to make, but apparently the
t:extension-point works much more logically than I was expecting, re-
rendering it's parent template. :)
[Header.tml]
<t:extend xmlns:t="http://tapestry.apache.org/schema/
tapestry_5_1_0.xsd">
<t:replace id="headerExtensionPoint">
<t:body/>
</t:replace>
</t:extend>
So my question is this, is there a component whose body can be swapped
out based on the presence of another component in the tree? Is it
possible to write one? It would be a shame to sacrifice the WYSIWYG
elegance just for the page title...
I suppose this is the way it is normally done:
http://code.google.com/p/shams/wiki/Component
--
Robert Hailey
Re: Modifying the title in a layout component
Posted by Josh Canfield <jo...@gmail.com>.
You could do something like this:
******** Layout.tml
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<t:delegate to="head"/>
</head>
<body>
<div class="container">
<div class="left-nav">yadayada</div>
<div class="content"><t:delegate to="body"/></div>
</div>
</body>
</html>
public class Layout {
@Property
private Block _head;
@Property
private Block _body;
@Inject
private ComponentResources _resources;
void setupRender() {
_head = getComponentBody("head");
_body = getComponentBody("body");
}
private Block getComponentBody(String id) {
final ComponentResources pageResources =
_resources.getPage().getComponentResources();
// Throws Exception if id doesn't exist... catch it if you
don't want to require the id
final Component head = pageResources.getEmbeddedComponent(id);
return head.getComponentResources().getBody();
}
}
********* Page.tml
<html t:type="layout"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head t:type="any" t:id="head">
<title>This is a wicked title</title>
<style type="text/css">
h1 {
color: red;
}
</style>
</head>
<body t:type="any" t:id="body">
<h1>This is the headline</h1>
</body>
</html>
On Wed, Mar 17, 2010 at 11:18 AM, Robert Hailey <ro...@cmediacorp.com> wrote:
>
> I'm using 5.1.0.5 and thought I could do something like this...
>
> [Page.tml]
> <html t:type="layout"
> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
> <head t:type="header">
> <title>My Page Title</title>
> </head>
> <body t:type="passthru">
> <h1>My Page Content</h1>
> </body>
> </html>
>
> The 'passthru' component was easy to make, but apparently the
> t:extension-point works much more logically than I was expecting,
> re-rendering it's parent template. :)
>
> [Header.tml]
> <t:extend xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
> <t:replace id="headerExtensionPoint">
> <t:body/>
> </t:replace>
> </t:extend>
>
> So my question is this, is there a component whose body can be swapped out
> based on the presence of another component in the tree? Is it possible to
> write one? It would be a shame to sacrifice the WYSIWYG elegance just for
> the page title...
>
> I suppose this is the way it is normally done:
> http://code.google.com/p/shams/wiki/Component
>
> --
> Robert Hailey
>
>
>
--
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org