-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement optional default for override_tag #125
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,21 @@ The override process has two parts: | |
1. Override your template tag with a mock implementation | ||
2. Define fake result for your tag in a `yaml` file | ||
|
||
|
||
### Providing a default value for template tags | ||
To provide a default for a template tag, you need to provide a keyword argument default when overriding your tag. | ||
|
||
``` | ||
from pattern_library.monkey_utils import override_tag | ||
|
||
override_tag(register, 'a_tag_name', default="https://potato.com") | ||
William-Blackie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
This default is used for any tag that's not passed its own context, allowing specificity for those elements that need it while preventing the tag from breaking when it's not structural to the component. | ||
|
||
#### limitation | ||
William-Blackie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Currently the default override is limited to direct references only i.e. {% a_tag_name page.url %} and not {% a_tag_name page.url as variable_name %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about the wording here. What's actually not supported is modifying context, so it might be better to say something along the lines of "Only providing a default for the output of the tag is supporting, it's not possible to modify context like <example of simpletag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point, thanks. |
||
|
||
### When do I need to override a template tag? | ||
|
||
Ideally your pattern library should be independent, so it doesn't fail when | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/default/default_html/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done