diff options
author | Dave Arter <davea@mysociety.org> | 2017-02-08 13:19:38 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2017-02-14 14:30:40 +0000 |
commit | b7443da57856dfa6295aad9c2cd3e69065553b70 (patch) | |
tree | 7baf6b069006e435c75edb278fb69c58e769b76c | |
parent | 4d5dda00af66ce32cbab8dc4d42466cace5e1022 (diff) |
Refactor main nav into reusable blocks
-rw-r--r-- | templates/web/base/footer.html | 30 | ||||
-rw-r--r-- | templates/web/base/main_nav.html | 35 | ||||
-rw-r--r-- | templates/web/base/main_nav_items.html | 44 |
3 files changed, 80 insertions, 29 deletions
diff --git a/templates/web/base/footer.html b/templates/web/base/footer.html index 5fd74b3a1..9f86f7519 100644 --- a/templates/web/base/footer.html +++ b/templates/web/base/footer.html @@ -9,35 +9,7 @@ <div class="nav-wrapper"> <div class="nav-wrapper-2"> - <div id="main-nav" role="navigation"> - <ul class="nav-menu nav-menu--mysoc"> - <li><a id="mysoc-logo" href="https://www.mysociety.org/">mySociety</a></li> - </ul> -[% - SET base = ""; - SET base = c.cobrand.base_url IF admin; -%] - <ul class="nav-menu nav-menu--main"> - <li><[% IF c.req.uri.path == '/' - %]span[% ELSE %]a href="[% base %]/"[% END %] class="report-a-problem-btn" - >[% loc("Report a problem") %]</[% c.req.uri.path == '/' ? 'span' : 'a' %]></li>[% - %]<li><[% IF c.req.uri.path == '/my' - %]span[% ELSE %]a href="[% base %]/my"[% END - %]>[% c.user_exists ? loc("Your account") : loc("Sign in") %]</[% c.req.uri.path == '/my' ? 'span' : 'a' %]></li>[% - %]<li><[% IF c.req.uri.path == '/reports' - %]span[% ELSE %]a href="[% base %]/reports[% IF c.user_exists AND c.user.categories.size %]?filter_category=[% c.user.categories.join(",") | uri | html %][% END %]"[% END - %]>[% loc("All reports") %]</[% c.req.uri.path == '/reports' ? 'span' : 'a' %]></li>[% - %]<li><[% IF c.req.uri.path == '/alert' - %]span[% ELSE %]a href="[% base %]/alert[% pc ? '/list?pc=' : '' %][% pc | uri %]"[% END - %]>[% loc("Local alerts") %]</[% c.req.uri.path == '/alert' ? 'span' : 'a' %]></li>[% - %]<li><[% IF c.req.uri.path == '/faq' - %]span[% ELSE %]a href="[% base %]/faq"[% END - %]>[% loc("Help") %]</[% c.req.uri.path == '/faq' ? 'span' : 'a' %]></li>[% - %]<li class="nav-menu__item--privacy"><[% IF c.req.uri.path == '/privacy' - %]span[% ELSE %]a href="[% base %]/privacy"[% END - %]>[% loc("Privacy") %]</[% c.req.uri.path == '/privacy' ? 'span' : 'a' %]></li> - </ul> - </div> + [% INCLUDE "main_nav.html" %] </div> </div> </div> <!-- .wrapper --> diff --git a/templates/web/base/main_nav.html b/templates/web/base/main_nav.html new file mode 100644 index 000000000..31bd61af5 --- /dev/null +++ b/templates/web/base/main_nav.html @@ -0,0 +1,35 @@ +[% + SET base = ""; + SET base = c.cobrand.base_url IF admin; + + # DEFAULT would make sense here, except it treats the empty string as falsy + # and some cobrands want to set ul_class to an empty string. + SET ul_class="nav-menu nav-menu--main" UNLESS ul_class.defined; +%] +[% BLOCK navitem ~%] + <li [% liattrs %]> + [%~ IF c.req.uri.path == uri ~%] + <span [% attrs %]>[% label %]</span> + [%~ ELSE ~%] + <a href="[% base %][% uri %][% suffix IF suffix %]" [% attrs %]>[% label %]</a> + [%~ END ~%] + </li> +[%~ END %] + +[% UNLESS omit_wrapper %] + <div id="main-nav" role="navigation"> +[% END %] + + [% UNLESS hide_mysoc_link %] + <ul class="nav-menu nav-menu--mysoc"> + <li><a id="mysoc-logo" href="https://www.mysociety.org/">mySociety</a></li> + </ul> + [% END %] + + <ul class="[% ul_class %]"[% " id='" _ ul_id _ "'" IF ul_id %]> + [% INCLUDE 'main_nav_items.html' %] + </ul> + +[% UNLESS omit_wrapper %] + </div> +[% END %] diff --git a/templates/web/base/main_nav_items.html b/templates/web/base/main_nav_items.html new file mode 100644 index 000000000..ca82b6560 --- /dev/null +++ b/templates/web/base/main_nav_items.html @@ -0,0 +1,44 @@ +[%~ INCLUDE navitem uri='/' label=loc('Report a problem') attrs='class="report-a-problem-btn"' ~%] + +[%~ IF c.user_exists ~%] + [%~ INCLUDE navitem uri='/my' label=loc('Your account') ~%] +[%~ ELSE ~%] + [%~ INCLUDE navitem uri='/auth' label=loc('Sign in') ~%] +[%~ END ~%] + +[%~ IF c.user_exists AND c.user.has_body_permission_to('planned_reports') ~%] + [%~ INCLUDE navitem uri='/my/planned' label=loc('Shortlist') ~%] +[%~ END ~%] + + +[%~ UNLESS hide_all_reports_link ~%] + [%~ + IF c.user_exists AND c.user.categories.size; + categories = c.user.categories.join(",") | uri; + cat_suffix = "?filter_category=" _ categories; + END; + + reports_uri = '/reports'; + IF body_name; + body_name = body_name | uri; + reports_uri = "${reports_uri}/${body_name}"; + END; + + INCLUDE navitem uri=reports_uri label=loc('All reports') suffix=cat_suffix; + ~%] +[%~ END ~%] + +[%~ + IF pc; + pc_uri = pc | uri; + pc_suffix = "/list?pc=" _ pc_uri; + END; + + INCLUDE navitem uri='/alert' label=loc('Local alerts') suffix=pc_suffix; +~%] + +[%~ INCLUDE navitem uri='/faq' label=loc('Help') ~%] + +[%~ UNLESS hide_privacy_link ~%] + [%~ INCLUDE navitem uri='/privacy' label=loc('Privacy') liattrs='class="nav-menu__item--privacy"' ~%] +[%~ END ~%] |