Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 5 and Version 6 of NonPackagedKidTemplates


Ignore:
Timestamp:
08/08/06 05:14:33 (13 years ago)
Author:
robinbryce
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NonPackagedKidTemplates

    v5 v6  
    148148== The critical trick == 
    149149 
    150 The problem not addressed so far is how to prevent TruboKid from complaining about your non packaged kid template file. And indeed,  how to prevent it from blowing up when it encounters 'bigsitesupport.tg/kid/welcome' as a template name. With the import hook installed this turns out to be pretty simple: in your tg-app.cfg file add `kid.precompiled=True` to the `[global]` section. If your config file was generated by runing tg-admin quickstart then after this change the first few lines of this file should look like: 
     150The problem not addressed so far is how to prevent TruboKid from complaining about your non packaged kid template file. And indeed,  how to prevent it from blowing up when it encounters 'bigsitesupport.tg/kid/welcome' as a template name. There are two parts to the trick:  
     151 
     152 1. To get TurboKid to actualy use your import hook: Add `kid.precompiled=True` to the `[global]` section of your turbogears app config file, `tg-app.cfg` in this example. If your config file was generated by runing tg-admin quickstart then after this change the first few lines of this file should look like: 
    151153 
    152154{{{ 
     
    161163}}} 
    162164 
     165 2. To pass TurboKid's initial sanity check on your template name you '''must''' create a subpackage under `bigsitesupport`, hence the use of `bigsitesupport.tg` throughout this example. 
     166 
     167 
    163168== Explanation == 
    164169 
    165 This works because when you tell TurboKid your template files are 'precompiled', TurboKid relies on pythons standard `__import__` machinery to load the template. By lying to turbokid about the 'precompiled' nature of your kid template you by pass all the 'is this kid file a proper pkg_resource' checks and instead go directly to your import hook. 
     170This works because when you tell TurboKid your template files are 'precompiled', TurboKid relies on pythons standard `__import__` machinery to load the template. But to get that far you need to pass the initial sanity check on your template name. Following this example, all your template references in your controller.py start with 'bigsitesupport.tg', so TurboKid finds the dot expects as a marker denoting which package your templates logicaly belong in. TurboKid does not do any further processing on the template name because it then sees that templates are flagged as precompiled and   invokes `__import__`. 
     171 
     172