Difference between revisions of "Xebra Master Pages"
(New page: Xebra Server Pages (.xeb) can be modularized with master pages (or templates). Usually a page has different regions which are dynamic and others which are static. These regions can be mode...) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | Xebra Server Pages (.xeb) can be modularized with master pages (or templates). Usually a page has different regions which are dynamic and others which are static. These regions can be modeled with xebra. To illustrate this we use a small example of a page with a static logo and a dynamic content. First we define the static master page: | + | [[Category:Xebra]] |
+ | [[Xebra About|About]] | [[Xebra Installation|Installation]] | [[Xebra Documentation|Documentation]] | [[Xebra Tutorial|Tutorials]] | [[Xebra FAQ|Frequently Asked Questions]] | ||
+ | |||
+ | ===Basics=== | ||
+ | |||
+ | Xebra Server Pages (.xeb) can be modularized with master pages (or templates). Usually a page has different regions which are dynamic and others which are static. These regions can be modeled with xebra. To illustrate this we use a small example of a page with a static logo and a dynamic content. First we define the static master page (master.xeb): | ||
<xml> | <xml> | ||
Line 9: | Line 14: | ||
</head> | </head> | ||
<body> | <body> | ||
− | <img href="logo.gif/> | + | <img href="logo.gif"/> |
− | <page: | + | <page:declare_region id="dynamic_content" /> |
</body> | </body> | ||
</html> | </html> | ||
</xml> | </xml> | ||
+ | |||
+ | and a concrete page which includes this master page (slave.xeb): | ||
+ | |||
+ | <xml> | ||
+ | <page:include template="master"> | ||
+ | <page:define_region id="dynamic_content"> | ||
+ | Some Content | ||
+ | </page:define_region> | ||
+ | </page:include> | ||
+ | </xml> | ||
+ | |||
+ | If we compile and display we will get the following page: | ||
+ | |||
+ | <xml> | ||
+ | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
+ | <html xmlns="http://www.w3.org/1999/xhtml"> | ||
+ | <head> | ||
+ | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
+ | <title>Foo</title> | ||
+ | </head> | ||
+ | <body> | ||
+ | <img href="logo.gif"/> | ||
+ | Some Content | ||
+ | </body> | ||
+ | </html> | ||
+ | </xml> | ||
+ | |||
+ | Quite obviously the declared region in master.xeb is filled with the defined region of slave.xeb. Notice that master.xeb will not be transformed to a servlet and will not be accesible from the browser since it is not complete. | ||
+ | Multiple regions can be declared per template. Furthermore including xeb pages can themselves declare new regions or transitively delegate their not implemented regions to their implementors. | ||
+ | |||
+ | ===Controllers=== | ||
+ | Templates can also be used to separate authenticated from unauthenticated content. If we take the example from above we can add access restriction by defining two regions and restricting the access to them: | ||
+ | |||
+ | <xml> | ||
+ | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
+ | <html xmlns="http://www.w3.org/1999/xhtml"> | ||
+ | <page:controller class="LOGIN_CONTROLLER" /> | ||
+ | <head> | ||
+ | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
+ | <title>Foo</title> | ||
+ | </head> | ||
+ | <body> | ||
+ | <img href="logo.gif"/> | ||
+ | <xeb:container render="%=authenticated%"> | ||
+ | <page:declare_region id="auth_content" /> | ||
+ | </xeb:container> | ||
+ | <xeb:container render="=%not_authenticated%"> | ||
+ | <page:declare_region id="not_auth_content" /> | ||
+ | </xeb:container> | ||
+ | </body> | ||
+ | </html> | ||
+ | </xml> | ||
+ | |||
+ | Similarly the slave.xeb would look like the following: | ||
+ | |||
+ | <xml> | ||
+ | <page:include template="master.xeb"> | ||
+ | <page:define_region id="auth_content"> | ||
+ | Welcome <xeb:display text="%=user%"/>! | ||
+ | </page:define_region> | ||
+ | <page:define_region id="not_auth_content"> | ||
+ | You are not authenticated. Go away! | ||
+ | </page:define_region> | ||
+ | </page:include> | ||
+ | </xml> | ||
+ | |||
+ | Notice that the user in xeb:display for a authenticated is retrieved from the same controller (instance) as the one in the master. If not overwritten by implementors the controller is inherited. If on the other hand one wants to use its own controller, it can be redefined in the slave page. |
Latest revision as of 08:42, 31 July 2009
About | Installation | Documentation | Tutorials | Frequently Asked Questions
Basics
Xebra Server Pages (.xeb) can be modularized with master pages (or templates). Usually a page has different regions which are dynamic and others which are static. These regions can be modeled with xebra. To illustrate this we use a small example of a page with a static logo and a dynamic content. First we define the static master page (master.xeb):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Foo</title> </head> <body> <img href="logo.gif"/> <page:declare_region id="dynamic_content" /> </body> </html>
and a concrete page which includes this master page (slave.xeb):
<page:include template="master"> <page:define_region id="dynamic_content"> Some Content </page:define_region> </page:include>
If we compile and display we will get the following page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Foo</title> </head> <body> <img href="logo.gif"/> Some Content </body> </html>
Quite obviously the declared region in master.xeb is filled with the defined region of slave.xeb. Notice that master.xeb will not be transformed to a servlet and will not be accesible from the browser since it is not complete. Multiple regions can be declared per template. Furthermore including xeb pages can themselves declare new regions or transitively delegate their not implemented regions to their implementors.
Controllers
Templates can also be used to separate authenticated from unauthenticated content. If we take the example from above we can add access restriction by defining two regions and restricting the access to them:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <page:controller class="LOGIN_CONTROLLER" /> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Foo</title> </head> <body> <img href="logo.gif"/> <xeb:container render="%=authenticated%"> <page:declare_region id="auth_content" /> </xeb:container> <xeb:container render="=%not_authenticated%"> <page:declare_region id="not_auth_content" /> </xeb:container> </body> </html>
Similarly the slave.xeb would look like the following:
<page:include template="master.xeb"> <page:define_region id="auth_content"> Welcome <xeb:display text="%=user%"/>! </page:define_region> <page:define_region id="not_auth_content"> You are not authenticated. Go away! </page:define_region> </page:include>
Notice that the user in xeb:display for a authenticated is retrieved from the same controller (instance) as the one in the master. If not overwritten by implementors the controller is inherited. If on the other hand one wants to use its own controller, it can be redefined in the slave page.