jTemplates: easy answers to dumb questions

I’ve been trying to use jTemplates for a fairly complex interface that displays quite a bit of data. The documentation on their site is pretty minimal, so I’ve come up with a lot of what may be very dumb questions that I’ve been forced to answer myself, by trial and error (how tacky).

I figured I would post these in hopes of saving someone else some wondering:

1. Can you treat an array like an array once it’s part of your template data?

Yep. In my data, Columns is an array, and this code works great:

<table class="{#if $T.Columns.length == 1}onecolumn{#/if}">
{#if $T.Columns[0].Label != null}
<thead>
...

2. Does whitespace matter?

Apparently not – see above.

3. How do you refer to a property of a parent object from a child template?

I couldn’t figure this out, so I worked around it by adding the property I needed to the root object I was passing into the child. I ended up doing this in a function because neither of the two delimiters jTemplates uses – {} and {#} – can be used for straight assignment as far as I could tell.

{#foreach $T.Columns as c_f}
{#include COLUMN_CELL root=addFieldType($T.c_f,$T.FieldType)}
{#/for}
...
function addFieldType(obj, ft) {
obj.FieldType = ft;
return obj;
}

4. Can I put a property of the current object into my call to a child template?

Seems like no. What I really wanted to do instead of the code above was this, which does not work:

{#foreach $T.Columns as c_f}
{#include COLUMN_CELL[$T.FieldType] root=$T.c_f}
{#/for}
...
{#template COLUMN_CELL[0]}
<td><input type="radio" disabled="disabled"/></td>
{#/template COLUMN_CELL[0]}
{#template COLUMN_CELL[1]}
<td><input type="checkbox" disabled="disabled"/></td>
{#/template COLUMN_CELL[1]}

For now, all I have is those four items.. I’m sure I’ll come up with more as I get into the hard parts.

1 Response to “jTemplates: easy answers to dumb questions”



  1. 1 the jTemplates experiment « garann means Trackback on June 9, 2010 at 5:50 pm

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




RSS Recent posts on the live version of this blog

  • giving greenfield stuff to newbs May 23, 2012
    I’m coming up on two months at my new job (feels like a lot less), and with the amount of code we have, that means there’s still plenty I haven’t seen or worked with. There are certain processes (e.g., deploying) that have become automatic, but others I haven’t yet done. I still get automated emails [...]
  • javascript hotline May 17, 2012
    I don’t know Rails, and that may be why I hadn’t heard of Rails Hotline before last week. If you’re not a Rails dev and are also unfamiliar, it’s pretty much what it sounds like: developers volunteer to take a shift answering the phone if anyone calls, and other developers can call in and ask [...]
  • authority and paying your dues May 11, 2012
    I’ve tried consulting a couple times. The most recent of those, I tried it with a partner. He didn’t know much about web development. I had to teach him a lot. He got significantly better, but he was still what I’d consider junior. At some point after we gave up on consulting, he was applying [...]
  • from mockup to code (efficiently) May 1, 2012
    Lately I find myself in the once-familiar position of taking mockups and converting them to markup and CSS. This is generally a pretty simple task, one you could optionally pass off to a junior dev. But that assumes there’s a clear process for it. Obvious divisions of labor, patterns, and best practices, I’m finding, make [...]
  • girl ghettos April 13, 2012
    The double-edged sword of trying to address the lack of women in technology as a woman is that, if you manage to get a group of technical women together, you’re going to end up creating what’s called a girl ghetto. A girl ghetto is where you stick the women you’re keeping around to show you’re [...]
  • a retirement fund for your javascript April 9, 2012
    You ever find yourself feeling unreasonably protective of JavaScript? I do. For a long time, JS lacked a lot of sophistication. It was vulnerable to being trampled over by bigger, more powerful technologies like Java applets or Flash. There was nothing to really commend it to anyone who didn’t, for whatever crazy reason, already love [...]
  • choosing template engines March 3, 2012
    The first presentation I ever gave at a conference was on templates. jQuery templates, specifically. It’s weird – it’s a topic I’ve never presented about again yet one that, if anything, I’ve become more obsessed with. So it stands to reason then that I still find myself in conversations about templates with other JavaScript dev […]
  • is it me or are we going backward? February 23, 2012
    Maybe it’s just me, but it feels like lately diversity is falling out of fashion as a goal in this industry. I made a tweet seeking sponsors for All-Girl Hack Night’s SXSW event earlier and was surprised by some of the responses. It seems like recent conferences have fewer female speakers, or are more defensive [...]
  • the $150k solution December 11, 2011
    An article was published yesterday in one of Austin’s local papers about Austin’s tech talent shortage. I was job hunting just a couple months ago and get a lot of calls from recruiters and hear about friends’ companies who are hiring and I think it’s pretty damned accurate. And by accurate I mean that it [...]
  • “girl” power November 16, 2011
    I just watched a short video called How to Get More Women in Tech in Under a Minute. The speaker, Caroline Drucker, is making a point about the toxicity of the word “girl” and how it hurts the cause of women in technology. Her argument is that every time we refer to ourselves as girls, [...]

Follow

Get every new post delivered to your Inbox.