views:

194

answers:

2

Hi,

I'm having a weird issue with a function I'm trying to call from within a jTemplates template giving the error "XYZ.getFriendlyName is not a function". It seems like I must have overlooked something simple, but I've tried everything I can think of and the error persists. The code looks like this:

<input type="text" value="{#if $T.RowId !== null}{XYZ.getFriendlyName($T.RowId)}{#/if}"/>

I've tried removing everything in the function to rule out a syntax error, renaming the function and moving it into the global namespace, moving the function itself into the page the template is on, before the template code.. Even putting everything in a ternary operator, which so far I haven't gotten to work at all in jTemplates. I continue to get the same error. Does anyone know a way I can fix this problem?

Thanks! Garann

A: 

In case anyone was curious, this was a timing and context issue. The jTemplate was getting processed before a JS file on the same page was fully read. Moving the function into the object that starts processing the top/first template fixed the problem.

garann
A: 
  1. Define function first:

    function getFriendlyName( param ){

    }

  2. Add function to param:

    $('template-name').setParam('getFriendlyName', 'getFriendlyName');

  3. Access function inside template by using $P like $P.getFriendlyName()

VallabhaV