Skip to content
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

adds conditional support to nested template objects #55

Merged
merged 1 commit into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/network_engine/plugins/template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ def _update(self, d, u):
else:
d[k] = v
return d

def _check_conditional(self, when, variables):
conditional = "{%% if %s %%}True{%% else %%}False{%% endif %%}"
return self.template(conditional % when, variables)
8 changes: 4 additions & 4 deletions lib/network_engine/plugins/template/json_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def run(self, template, variables=None):
key = self.template(item['key'], variables)

# FIXME moving to the plugin system breaks this
# when = item.get('when')
# if when is not None:
# if not self._check_conditional(when, variables):
# continue
when = item.get('when')
if when is not None:
if not self._check_conditional(when, variables):
continue

if 'value' in item:
value = item.get('value')
Expand Down