Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8277613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:44:09+00:00 2026-06-08T08:44:09+00:00

using template toolkit I have come up with the below. (I am running this

  • 0

using template toolkit I have come up with the below. (I am running this template multiple times on the one page.)

<table>
<tr>
    <th>Title</th>
</tr>
[% FOREACH t = Testing %]
    [% IF t.isEven %]
    <tr><td>Goodbye World</td></tr>
    [% ELSE %]
    <tr><td>hello world</td></tr>

    size() = [% loop.size %]</br>
    max () = [% loop.max %]</br>
    index () = [% loop.index %]</br>
    count () = [% loop.count %]</br>
    first () = [% loop.first %]</br>
    last () = [% loop.last %]</br>
    prev () = [% loop.prev %]</br>
    next () = [% loop.next %]</br>

    [% END %]
[% END %]
</table>
[% myJS %]

which outputs this. (i only included the first and last tr in here to save space).

<table>
    <tr>
        <th>Title</th>
    </tr>
<tr class="1"><td>hello world</td></tr>
size() = 5</br>
max () = 4</br>
index () = 0</br>
count () = 1</br>
first () = 1</br>
last () = 0</br>
prev () = </br>
next () = HASH(0x1d6daad0)</br>

<tr class="4"><td>hello world</td></tr>
size() = 5</br>
max () = 4</br>
index () = 4</br>
count () = 5</br>
first () = 0</br>
last () = 1</br>
prev () = HASH(0x1cbfda20)</br>
next () = HASH(0x1d6e9c10)</br>
</table>
<script src ="js/my.js"></script><table>

over and over until my loop is finished. Is there a way to only include [% myJS %] on the page once? as it is the same script?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:44:12+00:00Added an answer on June 8, 2026 at 8:44 am

    The code that you have shown us here only displays the my.js line once. It is outside of any loop so it can’t possibly be displayed more than once.

    If you’re getting it displayed more than once, then you’re not using the code that you are showing us. Or there is more code surrounding the code in your example. Do you perhaps have another loop which displays multiple tables?

    In general, the solution to your problem would be to move the code which displays the Javascript file outside of any loops – so it only displays once. If, however, that’s not an option for some reason (and I really can’t see why it wouldn’t be) then you can use the loop variable to only output the Javascript on the first (or, perhaps, the last) iteration of the loop. Something like this:

    [% FOR var IN list;
         var.something_useful;
         myJS IF loop.first;
       END %]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a calendar on my website, generated in Perl using Template::Toolkit and Template::Plugin::Date
I want to get a random number using template toolkit. It doesn't have to
I'm making a Perl website, and I'll using Template Toolkit (for the view), a
I'm using MVVM (MVVM Light Toolkit) and have a property on the view model
I have a page that has a listbox with the following item template as
I am experiencing weird behavior with template toolkit, say I have a data structure
I'm using AJAX Control Toolkit with Visual Studio 2005. I don't have the vs
I'm using the Silverlight Control Toolkit and trying to position the legend below the
I'm using an AutoCompleteBox from the WPF Toolkit inside a DataGridTemplateColumn's editing template in
By basic T4 template, I mean not using T4 Toolkit or any of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.