forked from rob-b/django-tagcon
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82f86d7
commit b508b88
Showing
3 changed files
with
88 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
======= | ||
Helpers | ||
======= | ||
|
||
AsTag | ||
===== | ||
|
||
.. currentmodule:: ttag.helpers | ||
|
||
.. class:: AsTag | ||
|
||
Assists with the common case of tags which want to add something to the | ||
context. | ||
|
||
For example, if you wanted a tag which would add a QuerySet containing a | ||
user's friends to the context (``{% get_friends user as friends %}``):: | ||
|
||
class GetName(ttag.helpers.AsTag) | ||
user = ttag.Arg() | ||
|
||
def output(self, data, context): | ||
return data['user'].friends_set.all() | ||
|
||
Some additional customization attributes to those which are provided in the | ||
standard ``Tag``'s :attr:`~ttag.Tag.Meta` class are available: | ||
|
||
.. class:: Meta | ||
|
||
.. attribute:: as_name | ||
|
||
Use some other argument name rather than the default of ``as``. | ||
|
||
.. attribute:: as_required | ||
|
||
Set whether or not ``as varname`` argument is required | ||
(defaults to ``True``). | ||
|
||
Two additional methods of interest are ``as_value``, which allows you to | ||
more completely customise output. | ||
|
||
.. method:: as_value(self, data, context) | ||
|
||
Returns the value you want to put into the context variable. | ||
By default, returns the value of :meth:`~ttag.Tag.output`. | ||
|
||
.. method:: as_output(self, data, context) | ||
|
||
Returns the data you want to render when ``as varname`` is used. | ||
Defaults to ``''``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ application. | |
|
||
install | ||
usage | ||
helpers | ||
reference |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters