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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:13:33+00:00 2026-05-26T20:13:33+00:00

In knockoutjs 1.2.1 I could do: <div data-bind=template: {name: ‘Bar’, foreach: persons, templateOptions:{fooMode: true}

  • 0

In knockoutjs 1.2.1 I could do:

<div data-bind="template: {name: 'Bar', foreach: persons, templateOptions:{fooMode: true} }"/>

<script id='Bar'>
    {{if $item.fooMode}} FOO! {{/if}}
</script>

Which I have tried to translate to knockout 1.3.0beta as

<div data-bind="template: {name: 'Bar', foreach: persons, templateOptions:{fooMode: true} }"/>

<script id='Bar'>
    <span data-bind="if: $item.fooMode">FOO!</span>
</script>

But the new native template engine doesn’t respect templateOptions.

Is there some other way I can pass arbitrary data into a template?

  • 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-05-26T20:13:33+00:00Added an answer on May 26, 2026 at 8:13 pm

    As you discovered, the native template engine does not support templateOptions which was a wrapper to the jQuery Template plug-in’s options functionality.

    Two ways that you could go:
    Place your data on your view model and use $root.fooMode or $parent.fooMode inside of your template. This would be the easiest option.

    Otherwise, if you don’t want the value in your view model, then you can use a custom binding to manipulate the context like:

    ko.bindingHandlers.templateWithOptions = {
        init: ko.bindingHandlers.template.init,
        update: function(element, valueAccessor, allBindingsAccessor, viewModel, context) {
            var options = ko.utils.unwrapObservable(valueAccessor());
            //if options were passed attach them to $data
            if (options.templateOptions) {
               context.$data.$item = ko.utils.unwrapObservable(options.templateOptions);
            } 
            //call actual template binding
            ko.bindingHandlers.template.update(element, valueAccessor, allBindingsAccessor, viewModel, context);
            //clean up
            delete context.$data.$item;
        } 
    }
    

    Here is a sample in use: http://jsfiddle.net/rniemeyer/tFJuH/

    Note that in a foreach scenario, you would find your options on $parent.$item rather than just $item.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My KnockoutJS template looks as follows: <div id=wrapper data-bind=template: { name:'theTemplate', foreach: cars(), beforeRemove:
If I had a template in KnockoutJs which is a 'foreach' template, when I
I'm trying to understand native knockoutjs template binding , especially foreach binding . Just
Let's say we have data as follows var data = { facets: [{ name
I am trying to understand if KnockoutJS will work for my application. My data
I just now start using knockoutjs. In below code am just trying to bind
How do we populate data in the knockoutjs view model on the first call
I have a jQuery template, and I would like to use a KnockOutJS template
I'm trying to use KnockoutJS to build an interactive dashboard with data bindings on
I just read about KnockoutJS and when I try to bind to sub-properties on

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.