<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Kirk Haines schreef:<br>
<blockquote
 cite="midf4cd26df0707091308m6e8d7e04g7adb49d339702312@mail.gmail.com"
 type="cite">
  <blockquote type="cite">
    <pre wrap="">
So if you want to access instance variables set in a controller, you
need to generate code to do that, and not do it directly.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
I've read this a couple of times, but I think I still need it
explained to me a bit more, because I am not quite sure I understand.

Let's say I have something....an online community site of some sort.
I want to have a little box in one corner of the page that shows the
time and date, whether the user has any new messages in their mailbox,
and some other stuff that may change regularly.

To be nice and modular, I want to have something like this in my page template:

&lt;InfoBox foo="bar" blah="snog" whatever="snow white" /&gt;

InfoBox is that thing with all that information.

Now, in InfoBox's template, are you saying that all the content has to
be generated programatically, because that template will only ever be
rendered once, so I can't just dynamically include data generated a
method call into it?  Or do I misunderstand you?
  </pre>
</blockquote>
I will give an example. Suppose your InfoBox depends on a user, if you
want to write this in your template:<br>
<br>
&lt;InfoBox user="@u" /&gt;<br>
<br>
Then you have to do something like this to make it work<br>
<br>
class InfoBox<br>
&nbsp; def render<br>
&nbsp;&nbsp;&nbsp; "&lt;div class="infobox"&gt;Unread messages :
\#{#{@user}.unread_messages}"<br>
&nbsp; end<br>
end<br>
<br>
The first time the page gets rendered an InfoBox instance is created,
and the instance variable @user is set to the string "@u". The render
method is called yielding:<br>
<br>
&nbsp;&nbsp;&nbsp; "&lt;div class="infobox"&gt;Unread messages :
#{@user.unread_messages}"<br>
<br>
This becomes part of your compiled template, which utilizes the @user
var set in your controller. Note how the outer interpolation is escaped
: \#{<br>
<br>
This is what I came up with, and I think it's messy, but it works.
Having talked about it a bit on IRC with Manveru and Jonathan I get the
impression this is not the primary usecase. You can also use it to
rewrite the part of your template inside the tag. Looked at it this way
you can add custom preprocessing to whatever is inside
&lt;Element&gt;...&lt;/Element&gt;. Manveru called it 'Aspect oriented
programming for templates'. It 'wraps' a piece of your template, doing
stuff with it.<br>
<br>
For the InfoBox usecase, judging from the blog example I'd say G
prefers to use &lt;?include href="infobox" ?&gt; which just reminds me
too much of rails partials, but even worse. Elements seem so nice and
clean for this on first sight, but the fact that they're rendered only
once makes it cumbersome. Maybe we need another compiler filter for
'dynamic' elements?<br>
<br>
This is one of the things where I'm very curious myself what their
primary intended use is. Maybe G or manv or Jo or someone else could
give more good examples of their usefulness, including what to do with
the @_children.<br>
<br>
One idea I had was to declare 'widgets' with besides the render method
also have a css and a javascript method. the outer Page element joins
all the css and javascript together and puts it in the header, creating
reusable components (sort of).<br>
<br>
Any other wild ideas? Insights?<br>
<br>
(ab)<br>
<br>
<pre class="moz-signature" cols="72">-- 
Arne Brasseur
<a class="moz-txt-link-freetext" href="http://www.arnebrasseur.net">http://www.arnebrasseur.net</a>
<a class="moz-txt-link-abbreviated" href="mailto:arne@arnebrasseur.net">arne@arnebrasseur.net</a></pre>
</body>
</html>