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 9090881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:28:44+00:00 2026-06-16T22:28:44+00:00

I’m planning to convert a Knockout based page to native templating. However, I have

  • 0

I’m planning to convert a Knockout based page to native templating. However, I have a couple of questions about the limitations of native templating compared to jQuery Templates.

With Knockout native templating can I reference a function within an ‘if’ control?

jQuery Templates:

 {{if GetFirstWord(ProductName) == "Premier"}}

Native Templates (is this possible)

<!-- ko if: GetFirstWord(ProductName) == "Premier" -->

Also, can I access an indexer like this using native templating:

{{each(i, d) Benefits}}
  <div class="{{if i%2==0}}even{{else}}odd{{/if}}">
{{/each}}
  • 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-16T22:28:45+00:00Added an answer on June 16, 2026 at 10:28 pm

    First one: Yes, it’s possible, and most likely you won’t need to change much code. However, you might want to do anyway in order to suit a better architecture in KnockoutJS. It’s not only for KO, but also a better design pattern that’s more maintainable.

    For instance, this

    <!-- ko if: GetFirstWord(ProductName) == "Premier" -->
    

    has the same functionality than

    <!-- ko if: currentWordisPremier -->
    

    and in your code you have something like

    self.currentWord = ko.observable("");
    self.currentWordisPremier = ko.observable(false);
    self.currentWord.subscribe(function(newCurrentWord){
      if(newCurrentWord === "Premier") self.currentWordisPremier(true);
    });
    

    (This was a quick example, you can design your code in a more scalable way through dynamic templating)

    Second one: Yes, but only from version 2.1 through the $index keyword. You can read more about the discussion here and some documentation here.

    As with the first point, you might want to change some of your javascript code to not give the template that much logic.

    {{each(i, d) Benefits}}
      <div class="{{if i%2==0}}even{{else}}odd{{/if}}">
    {{/each}}
    

    in native KnockoutJS templating

    <!-- ko foreach:Benefits -->
      <!-- ko if: $index %2 == 0 -->
      <div class="even"> ... </div>
      <!-- /ko -->
      <!-- ko ifnot: $index % 2 == 0 -->
      <div class="odd"> ... </div>
      <!-- /ko -->
    <!-- /ko -->
    

    a better approach could be

    <!-- ko foreach:Benefits -->
      <div data-binding="css: {"even" isEven, "odd": isOdd}"> ... </div>
    <!-- /ko -->
    

    and you do the logic in your js, maybe just once for your array.

      var index = 0;
      var updatedBenefits = ko.utils.arrayForEach(self.Benefits(), function(benefit) {
         var property = index++ %2 == 0 ? "isEven" : "isOdd";
         return benefit[property] = true;
      });
      self.Benefits(updatedBenefits)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a jquery bug and I've been looking for hours now, I can't

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.