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

Providing parameters for includes #254

Closed
tyfairclough opened this issue Sep 30, 2016 · 1 comment
Closed

Providing parameters for includes #254

tyfairclough opened this issue Sep 30, 2016 · 1 comment

Comments

@tyfairclough
Copy link

Hi folks,

How do I pass a parameter or variable to an include.

I have a breadcrumb I use over and over, but I want to pass a variable to it from page to page.

{% include "includes/secondary-nav.html" %}

could I add something like

{% include "includes/secondary-nav.html" var ="something" %}

Any ideas?

@vickytnz
Copy link

vickytnz commented Sep 30, 2016

You need to use a macro.

I've actually been doing this now:

IN AN INCLUDES FILE CALLED breadcrumbs.html

{% macro breadcrumb(title) %}
<div class="breadcrumbs">
<ol>
<li><a href="/">STATIC TITLE</a></li>
{% if title %}
<li>{{title}}</li>
{% endif %}
</ol>
</div>
{% endmacro %}

ON THE PAGE

{% import "includes/breadcrumbs.html" as breadcrumbs %}
{{ breadcrumbs.breadcrumb('Pre-task') }}

Alternatively, if you can add it as an include in another way, then you can use set variable at the start and not use a variable

<div class="breadcrumbs">
<ol>
<li><a href="/">STATIC TITLE</a></li>
{% if title %}
<li>{{title}}</li>
{% endif %}
</ol>
</div>
{{set title="pre-task"}} <!-- ORDER IS IMPORTANT, THIS HAS TO BE FIRST -->
{% import "includes/breadcrumbs.html" %}

gemmaleigh added a commit that referenced this issue Oct 25, 2016
https://github.com/alphagov/govuk_template/blob/master/CHANGELOG.md

- Remove external link styles (PR #231)
- Remove extraneous copy of HTML5shiv that wasn’t being used (PR #254)
- Update govuk_frontend_toolkit to latest version (PR #256)
gemmaleigh added a commit that referenced this issue Oct 25, 2016
https://github.com/alphagov/govuk_template/blob/master/CHANGELOG.md

- Remove external link styles (PR #231)
- Remove extraneous copy of HTML5shiv that wasn’t being used (PR #254)
- Update govuk_frontend_toolkit to latest version (PR #256)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants