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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:13:14+00:00 2026-06-16T05:13:14+00:00

I have a view that needs different templates for different models. I’m implementing a

  • 0

I have a view that needs different templates for different models.

I’m implementing a payment provider configuration, and it requires a different set of options for different payment providers.

Here is what I have now in my view code:

robokassa: JST["payment_providers/robokassa"]
cash: JST["payment_providers/cash"]

render: =>
  template_name = @model.get('name')
  switch template_name
    when "robokassa" then $(@el).html(@robokassa(payment_provider: @model))
    when "cash" then $(@el).html(@cash(payment_provider: @model))        

It works, but it’s ugly.

I tried something like this, but I can’t find a definitive manual on how to use the JST object except for the simple use cases:

render: =>
  template_name = @model.get('name')
  $(@el).html(JST["payment_providers/#{template_name}"](payment_provider: @model)

This returns an error that says it’s not a function.

I guess, ideally, the solution would look like

template: => 
  JST["payment_providers/#{@model.get('name')}"](payment_provider: @model)
...
render: =>
  $(@el).html(@template())

But I can’t figure out how to correctly write it.

Update

The latter is indeed correct, the gotcha was that @model wasn’t loaded when render was called.

  • 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-16T05:13:15+00:00Added an answer on June 16, 2026 at 5:13 am

    You CoffeeScript syntax seems fine to me.

    The difference between your first (working) sample and the two others is, that in the first code sample the JST object is accessed when your class is evaluated, and in the two latter samples only when the view is rendered.

    Could the state of the JST object have changed in between so that the templates are no longer present at render time?

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

Sidebar

Related Questions

I'm using Drupal 6. I have a custom view that needs to be filtered
I have an app that needs backgrounds for both parts of the split view.
I have a View that contains a ParentModel, which contains 2 Models. I only
I have a lotus view that stores a number. I need to perform some
I am beginner in rails. I have view that i try to print inside
I have a view that has a column to make it sortable. When clicking
I have a view that renders a list elements using the following template :
I have a view that shows user profile fields in a tabular format. There
I have a view that is used in a UINavigationController and and is automatically
I have a View that is basically setup like this: <Grid> <ViewBox> <Grid> <ItemsControl

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.