SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smarty Template syntax error

    If you want the full code --> http://pastebin.com/m6ca41d10

    PHP Code:
    {foreach from=$completed_semester_classes key=a item=b}
            <
    tr class="{cycle values='odd,even'}" style="font-size:0.8em;">
                    <
    td>{$form_data.{$a}_complete_sem.html}</td>
            </
    tr>
    {/foreach} 
    Gives me the error:
    Code:
    Fatal error: Smarty error: [in /apps/home/psychology/admissions_1.0/public/view/templates/admission.tpl.php line 90]: syntax error: unrecognized tag: $form_data.p{$a (Smarty_Compiler.class.php, line 446) in /apps/home/itwdid/lib/Smarty-2.6.18/libs/Smarty.class.php on line 1095
    How can I get Smarty to recognize that I'm wanting to include the key of my array as part of the object I'm trying to call?

    I'm trying {$form_data.p{$a}_complete_year.html} to accomplish {$form_data.p103_complete_year.html} and so on.
    Last edited by apinomus; Dec 4, 2007 at 14:23.

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2005
    Location
    Nashville, TN
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the Smarty syntax for the foreach function is->
    Code:
    {foreach from=$data  key=key item=item}
     {$key.value} //value being the name of the field in the array
     {$item.value}
    {/foreach

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmm001 View Post
    the Smarty syntax for the foreach function is->
    Code:
    {foreach from=$data  key=key item=item}
     {$key.value} //value being the name of the field in the array
     {$item.value}
    {/foreach
    Thanks for the response pmm001. If I call just {$a} inside the foreach, it properly echo's back my array's key number, so my foreach syntax that is not the problem.

    {$form_data.p{$a}_complete_sem.html} is the problem code here. For example, I want it to write {$form_data.p103_complete_sem.html} then load the HTML in for that input. How can I do that?

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2005
    Location
    Nashville, TN
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    good question! have you asked on the Smarty forum?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmm001 View Post
    good question! have you asked on the Smarty forum?
    Yep! http://www.phpinsider.com/smarty-for...ic.php?p=46365
    Quote Originally Posted by pmm001 View Post
    this worked in one of my tps
    Code:
    {$form_data.p}{$a}_complete_sem.html
    Using that code echo's text: 102_complete_sem.html
    I'm needing it to resolve to the HTML for the element.

  6. #6
    SitePoint Zealot
    Join Date
    Nov 2005
    Location
    Nashville, TN
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this worked in one of my tps
    Code:
    {$form_data.p}{$a}_complete_sem.html

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bump, still wondering how to do this.

  8. #8
    SitePoint Zealot
    Join Date
    Nov 2005
    Location
    Nashville, TN
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where is the value of {$form_data.p} coming from? have you used the debug console to verify template variables?


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
  •