I'm wondering if anyone has any good ideas on how to generate URLs in
JavaScript code that take into account the application's URL prefix.
What I've done is implement a couple of JS helpers to sort-of mimic
`pylons.url`, and this seems to work pretty well.
In my Mako template, I do this:
<script>
var MY_NAMESPACE_CONFIG = {/* config values */};
MY_NAMESPACE_CONFIG.urls = {
prefix: '${url("/").rstrip("/")}'
};
</script>
And in my util code, there's this function:
url: function (path, params) {
// It's assumed that ``path`` starts with a forward slash
path = [MY_NAMESPACE_CONFIG.urls.prefix, path].join('');
if (params) {
var query_string =
my_namespace.util.paramsToQueryString(params);
path = [path, query_string].join('?');
}
return path;
}
Not that this is overly complicated, but does anyone know of a better
or simpler approach?
On a related note, how do you pass config values from Pylons to your
JavaScript code? I convert a subset of my Paste config to JSON in
`load_environment` and decode it in the template.
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.