On Nov 9, 9:20 am, Rodrigo Moraes <[email protected]> wrote:
> On Sun, Nov 8, 2009 at 10:35 AM, Vinay Sajip wrote:
> > Is there a simple solution for my problem which I'm missing?
>
> To be honest, I don't understand the problem entirely.
>
It's not a common situation, perhaps - most applications are
monolithic where everything knows about everything else. Consider:
<!-- public/layout.html, part of Public component -->
{{ url_for('static', file='style.css') }}
{% block content %}{% endblock %}
<!-- faq/faq.html, part of Faq component -->
{% extends public/layout.html %}
Here's some <a href="{{ url_for('news') }}"news</a>.
Each component is developed separately, no dependencies other than the
"extends". At deployment time, they're plugged together so that all
Public endpoints are prefixed by "public/" and all Faq enpoints are
prefixed by "faq/".
The endpoints referenced in the templates are purely local (since the
components are not aware of the big picture) but at run-time, the
url_for implementation needs to convert the first url_for to a call to
adapter.build("public/static") whereas the second url_for needs to be
converted to a call to adapter.build("faq/news").
> But it seems that you should consider rendering the components
> separately, each with their own context.
The problem is that templates defined by components can extend/include
templates defined by other components. A single render call will thus
include fragments from many different templates defined by different
components.
The crux of the problem is that endpoint prefixes are only known at
site deployment time, not at template development time, and while you
could certainly modify the templates to hard-code the endpoints, that
defeats the object of aiming to have a generic system with
dependencies minimised, and fixes those templates for use in that
specific deployment only.
In my system each component knows the endpoint prefix it's deployed
with, and it also provides a loader for its templates. So, I can get
from template -> component which loaded it -> endpoint prefix of
component. But I don't know a way of accessing, at render time, the
template a fragment was lexically defined in, from within the template
itself. I'm looking for a magic variable e.g. "__template__" which, if
referenced in some template fragment, returns a reference to the
template in which that fragment was defined.
Of course the Jinja implementation sensibly keeps the run-time/render-
time stuff separate from the template-compile-time stuff, but in this
case a bridge from the run-time to the defining template would be
nice. I have looked at the documentation to see if a variable such as
__template__ exists, but I've not found it.
Regards,
Vinay Sajip
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pocoo-libs" 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/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---