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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:10:56+00:00 2026-06-06T04:10:56+00:00

I am developing a simple pyramid application where I am using JQuery to do

  • 0

I am developing a simple pyramid application where I am using JQuery to do AJAX requests. I have until now had my javascript code within my chameleon templates. Now I want to extract my javascript into another location (e.g. as static resources).

My problem is that I find my javascript code relies on dynamically generated content like so:

$.post("${request.route_url('my_view')}",{'data': 'some data'}, function(html){
    $("#destination").html(html);
});

The dynamic element being:

"${request.route_url('my_view')}"

Which is calling the route_url method of the request object within the template.

Is there a recognised pattern for separating such javascript files into their own templates and providing routes and views for them or do I simply keep my javascript in my page 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-06-06T04:10:57+00:00Added an answer on June 6, 2026 at 4:10 am

    Yes; you generally put context-specific information like expanded routes into the templates and access this information from your (static) JavaScript libraries.

    Including the context info can be done in various ways, depending on taste:

    1. You could use a data attribute on a tag in your generated HTML:

      <body data-viewurl="http://www.example.com/route/to/view">
          ...
      </body>
      

      which you then, in your static JS code load with the jQuery .data() function:

      var viewurl = $('body').data('viewurl');
      
    2. Use a made-up LINK tag relationship to include links in the document head:

      <head>
          <link rel="ajax-datasource" id="viewurl"
                href="http://www.example.com/route/to/view" />
          ...
      </head>
      

      which can be retrieved using $('link#viewurl').attr('href'), or $('link[rel=ajax-datasource]').attr('href'). This only really works for URL information.

    3. Generate JS variables straight in your template, to be referenced from your static code:

      <head>
          ...
          <script type="text/javascript">
             window.contextVariables = {
                 viewurl = "http://www.example.com/route/to/view",
                 ...
             };
          </script>
      </head>
      

      and these variables are referable directly with contextVariables.viewurl.

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

Sidebar

Related Questions

Im developing a simple console Application using java. The code is given below `
im developing a simple Mxml application using flex 3. I have used simple text
I have been developing simple web services and clients using JBoss but now I
I'm developing simple VS 2008 addin. Now I have only autogenerated code of base
I'm developing a simple page with Symfony2, using Twig as template engine. I have
I'm developing a simple Facebook application, and now I need to create a page
I have 6 months experience with Android, developing simple UI-based applications. Now I want
Im developing a simple console application using java. I want to display currently running
Im developing a simple application that have a line like this: string[] values =
I'm developing a simple, training application with Spring MVC and Hibernate. I'm using Maven

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.