Hi list,

ok, after having searched for a while, that was really easy.

In the environment.py I could just add the additional path to the search
path:

def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=["/etc/myapp/customized-templates",
os.path.join(root, 'templates') ])

I think it is important that the "/etc/myapp/customized-templates" is
located before os.path.join(root, 'templates'), so that the customized
template will be found before the default template.
Thus I even do not need to change my render code. As soon as a template
in /etc/myapp/custom... exists, this will be used... but, it the
customized template contains an error there will be no fallback to the
original template.

Kind regards
Cornelius

Am 24.10.2011 10:22, schrieb Cornelius Kölbel:
> Hi there,
>
> I am (still) using pylons with the mako templating engine.
> I got several render("/thispage.mako") calls in my pylons controllers.
> The thispage.mako template is part of my pylons based project and I am
> using the render call from pylons.templating.
>
> I'd like to provide the possibility to customize the look and feel
> without having to alter the original mako templates. So my idea was to
> provide a "mytemplates" folder, that may contain a customized template
> "thispage.mako".
>
> My idea was to then check, if the customized version exists, and then
> render this version but otherwise render the original one:
>
> try:
>     render("/mytemplates/thispage.mako")
> except:
>     render("/thispage.mako")
>
> But the customized themplate /mytemplates/thispage.mako is not known to
> my pylons project, when I add it after creating the python package.
>
> Any ideas on this?
> Maybe the basis of my approach is not that optimal?
>
> Thanks a lot and kind regards
> Cornelius
>


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to