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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:08:17+00:00 2026-05-16T09:08:17+00:00

I’m using jQueryUI and jQuery-tmpl, but I believe the advice I’m looking for is

  • 0

I’m using jQueryUI and jQuery-tmpl, but I believe the advice I’m looking for is broad enough it’d apply to any sort of templating library.

The problem I have is that I’ll often have some sort of CRUD widget in my template

<script id="some-widget-template">
<div class="some-widget">
 <input name="NameField"/>
 <button id="some-widget-save">Save</button>
</div>
</script>

That leaves me with a very readable widget I can go back and edit, etc. Except that it is ugly. Using jQueryUI I can make the button very pretty, but it requires some Javascript. So in my corresponding Javascript controller, my code will look like this:

$("#some-widget-template")
        .render( arrayOfDataObjects )
        .appendTo("body");
$("#some-widget-save").button();

For that very simple example, this works fine. My controller, however, will quickly become cluttered the more elements that need transforming. It also feels like this should be the concern of the view / templating engine, not to mention having magic strings (“#some-widget-save”) that degrade the maintainability of the code.

What’s the best way to go about this? Surely I can’t be the first person to run into this problem. I’ve hacked together jquery-tmpl so that before returning a jQuery object, it’ll scan for a button element, and if it encounters it, to transform it to a proper button element. This seems slow, as it’ll have to traverse each element in the template. Any ideas?

Edit: I found that when using CSS3, 90% of my problems were eliminated. When building for non-CSS3 compliant browsers, I make use of the factory method.

  • 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-16T09:08:17+00:00Added an answer on May 16, 2026 at 9:08 am

    Disclaimer: the first time I’ve heard of jQuery-tmpl is while reading your question.

    Based on my understanding of your problem, I would try to structure my widget instantiation such that the changes are set to happen automatically and broadly for all elements on any given page that match certain parameters.

    You could include a UI initialization function in your framework that, when called, looks at all the elements of the DOM that you tell it to, and then turns them into jQuery UI widgets. The flow would go something like..

    1. jQuery-tmpl goes through and converts all your data into the appropriate templated output.
    2. After jQuery-tmpl has run its course, a call to your instantiation method – let’s say “renderUI()” – is made.

    jQuery-tmpl would spit out a series of structured elements based on your data…

    <div class="some-widget">
        <input name="NameField"/>
        <button class="reset-button">reset</button>
        <button class="save-button">Save</button>
    </div>
    
    <div class="tabbed-widget">
        <ul>
            <li>one</li>
            <li>two</li>
            <li>three</li>
        </ul>
    </div>
    

    The instantiation method could look something like…

    function renderUI() {
    
        $('.some-widget > .save-button').button({/* options */});
        $('.tabbed-widget > ul').tabs({/* options */});
        /* ... continue any other types of widget instantiation ... */
    }
    

    If you are instantiating UI elements selected by class, rather than ID, you can put as many of them as you want into the document, and they’ll all get instantiated “at once,” since jQuery will select all of them and apply the UI Widget constructor to them.

    If you need to run some pre-processing code (such as jQuery-tmpl) before those widgets get instantiated, you can encapsulate your initialization of widgets and call it once all the jQuery-tmpl processing is out of the way.

    Anyway, I hope this helps!

    P.S. Maybe this is something related to jQuery-tmpl (although I can’t fathom what), but it appears that your widget is composed of DOM elements within a script tag. Something about that seems extremely irregular to me ;P

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

Sidebar

Related Questions

No related questions found

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.