SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    template values won't render when contained within <> of markup

    I have an array that looks similar to:

    Code:
    var myData = [
    { hrefVal : 'mypage.php', lnkTxt : 'My Page' }
    ]
    Then I'm using:

    Code:
    $.template( 'tpl_gNav', '<li><a href="/$(hrefVal)" class="nav">${lnkTxt}</a></li>' );
    
    $.tmpl( 'tpl_gNav', myData ).appendTo( '#cGnav ul' );

    I am expecting the resulting markup to be rendered as:
    HTML Code:
    <li><a href="/mypage.php" class="nav">My Page</a></li>
    but instead, I'm getting:

    Code:
    <li><a href="/$(hrefVal)" class="nav">My Page</a></li>

    I can't seem to get any values to be displayed as attribute values within the markup. Can anyone see what I'm doing wrong?

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,825
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Is it because you have hrefVal in parenthesizes instead of brackets? ie: (hrefVal) should be {hrefVal}?

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow. i've def been sitting in front of the computer for too long... thanks!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •