Skip to content
This repository
Browse code

Add more docs and example about app_globals and tmpl_context

  • Loading branch information...
commit f284228e721ef757c845846f8fccb5c65b94e499 1 parent 821fd09
Alessandro Molina authored April 03, 2012

Showing 1 changed file with 21 additions and 1 deletion. Show diff stats Hide diff stats

  1. 22  docs/main/explorequickstart.rst
22  docs/main/explorequickstart.rst
Source Rendered
@@ -710,6 +710,13 @@ every single request that reaches your app.   So you can easily use it to
710 710
 do app wide things (it arleady sets up the identity attribute on the
711 711
 request with information about the user pulled from the WSGI environ.)
712 712
 
  713
+This provides also a valid example of the ``tmpl_context`` object which
  714
+can be used to keep around variables that need to be passed to the view
  715
+from somewhere that doesn't have direct access to the view itself.
  716
+
  717
+The ``tmpl_context`` object is always available inside the view itself
  718
+with the same name.
  719
+
713 720
 helpers.py
714 721
 ~~~~~~~~~~~~
715 722
 
@@ -734,7 +741,8 @@ template helpers and stick them here.
734 741
 globals.py
735 742
 ~~~~~~~~~~~~
736 743
 
737  
-Every app may have some global settings or information that's shared across all requests, but it's very possible that you may want to run two TG2 apps in the same process, or even two instances of the same app in a single process.  If so, ``app_globals.py`` provides a simple mechanism for storing application specific globals which don't clober on other instances of the same app.
  744
+Every app may have some global settings or information that's shared across all requests, but it's very possible that you may want to run two TG2 apps in the same process, or even two instances of the same app in a single process.
  745
+If so, ``app_globals.py`` provides a simple mechanism for storing application specific globals which don't clober on other instances of the same app.
738 746
 
739 747
 .. code-block:: python
740 748
 
@@ -754,6 +762,18 @@ The ``app_globals`` and ``helpers`` stuff is pre-loaded up into the tg
754 762
 environment for you by the config system.   Which is what we will
755 763
 look into next.
756 764
 
  765
+The globals will then by available using ``tg.app_globals`` anywhere inside
  766
+your application:
  767
+
  768
+.. code-block:: python
  769
+
  770
+    from tg import app_globals
  771
+
  772
+    class RootController(BaseController):
  773
+        @expose()
  774
+        def somewhere(self):
  775
+            return str(app_globals.somevalue)
  776
+
757 777
 Config
758 778
 ------------
759 779
 

0 notes on commit f284228

Please sign in to comment.
Something went wrong with that request. Please try again.