|
DirectoryOfBricks
A directory of HTML bricks, available out of the box.
Core BricksThese come part of the core distribution:
+ Self rendering bricks will ignore the HTML tag they annotate ExamplesThis section provides a bit more detail on how to use these bricks. Repeat brickThis brick is perfect for projecting a template fragment across a collection. Let's say you have a List<Movie> movies in your page class, and you want to print them out in an unordered list: <ul>
@Repeat(items=movies, var="movie")
<li>${movie.name}</li>
</ul>For the scope of the repetition, movie becomes the context. In order to access the outer page object, you must use the scope variable pageVar. For example: <ul>
@Repeat(items=movies, var="movie", pageVar="actor")
<li>${actor.name} starring in ${movie.name}</li>
</ul>The pageVar (if left out) will default to page. Nesting repeat bricks results in dynamic scoping of pageVar. The repeat brick can repeat over any subtype of java.util.Collection. Require brickThe require brick is basically useful in embedding pages that have a javascript, css or other external dependency that must be included in the target page. For instance, let's say you have a script called ajax.js which provides some ajax functionality that you use in your page: <html>
<head>
<script type="text/javascript" src="ajax.js"> </script>
</head>
<body>
<!-- some cool ajax stuff here -->
</body>
</html>Now you can wrap this brick and reuse it in any of your pages using the @EmbedAs annotation on your java page classes. Learn how to do this in EmbeddingBricks. But this does not give us the linked script (remember anything outside <body> is discarded when embedding). So to get around that we use the @Require annotation as follows: <html>
<head>
@Require
<script type="text/javascript" src="ajax.js"> </script>
</head>
...This tells Sitebricks to render the <script> tag in the <head> of any pages that embed this page. Sitebricks is also smart enough to remove multiple occurrences of the same @Require brick (matched by string equality), so you don't render duplicates when embedding a brick multiple times in the same page. This is known as tag interning. | ||||||||||||||||||||||||
Any thought for a 'select' brick ? Would be glad to code one :)
Can you access the @Repeat index variable? How would you use the @Repeat construct when there's no tag to annotate? eg iterate a list in a javascript function
N00b question - any tutorials/examples on how to use the @Include tag?