eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

How to not expand variables fully with njk

Open nikivdev opened this issue 5 years ago • 2 comments

I want to replicate the header from my site in eleventy: https://nikitavoloboev.xyz It looks like:

image

In my navigation.njk I have this line {{ nav.data.navtitle }}

This expands over all the templates I have that have navtitle property. But I want to mix in some links that are just links. i.e. wiki in example above links externally. Then after, I have Likes and that is internal to Eleventy again.

I am not sure what is the clean way to solve this issue.

nikivdev avatar Jun 16 '20 03:06 nikivdev

Full code for the url is actually

  <div class="nav__content">
    <ul class="nav__menu js-nav-menu" id="nav-menu">
      {%- for nav in collections.nav -%} {%- set isCurrent = (nav.url ==
      page.url) -%} {%- set isParent = nav.url != '/' and page.url and nav.url
      in page.url -%}
      <li
        class="nav__item{% if isCurrent or isParent %} nav__item--active{% endif %}"
      >
        <a
          href="{% if isCurrent %}#main{% else %}{{ nav.url | url }}{% endif %}"
          class="nav__link"
          {%
          if
          isCurrent
          %}aria-current="page"
          {%
          endif
          %}
        >
          {{ nav.data.navtitle }}
        </a>
      </li>
      {%- endfor -%}
    </ul>
  </div>

nikivdev avatar Jun 16 '20 03:06 nikivdev

So I do want to keep the set isCurrent logic to indicate which tab is active:

image

But still adding a link inbetween the nav entries

nikivdev avatar Jun 16 '20 03:06 nikivdev

Unfortunately this issue slipped under the radar—I’m finally circling back through some of the really old issues on the tracker and am unfortunately declaring issue bankruptcy on these—sorry! If you feel like this issue is still relevant, feel free to reopen a new issue with the same exact content! Appreciate your understanding!

zachleat avatar Nov 21 '25 18:11 zachleat