Coder Social home page Coder Social logo

Comments (5)

 avatar commented on August 29, 2024 1

Until this feature is added in a more graceful way you could use the hacky solution below.

Base Template Example

{{--*/ $activeNav = 'nav-2' /*--}}

@section('body')
    @include('_common.navigation')
    <h1>Hello World</h1>
@endsection

Included Navigation Template Example

<ul>
    <li{!! $activeNav == 'nav-1' ? ' class="active"' : '' !!}>Nav 1</li>
    <li{!! $activeNav == 'nav-2' ? ' class="active"' : '' !!}>Nav 2</li>
    <li{!! $activeNav == 'nav-3' ? ' class="active"' : '' !!}>Nav 3</li>
</ul>

from jigsaw.

adamwathan avatar adamwathan commented on August 29, 2024

Not at the moment but this is a good idea, I will try and get this in really soon.

from jigsaw.

avishwakarma avatar avishwakarma commented on August 29, 2024

Thanks @adamwathan that would be a great help to use the Jigsaw as full fledged static site builder.
Looking forward to get this done soon.

from jigsaw.

jevets avatar jevets commented on August 29, 2024

Harp does a nice job of this, making a current variable available to all views.

For page /about/team, generated from file about/team.md, for example:

current.source
// (string) 'team'

current.path
// (array) ['about', 'team']

This is usually enough to determine the current active page and even its active parent page/section.

I'm going to take a stab at a larger site with Jigsaw over the next couple weeks, so I'll post back if I find a nice way of adding this behavior, too.

Also for nav item classes, I usually clean up the ternary operator like so (think I saw Taylor Otwell do this somewhere). It's just cleaner to me:

<li class="{{ $activeNav != 'nav-1' ?: 'active' }}">...</li>

from jigsaw.

damiani avatar damiani commented on August 29, 2024

As of v1.0.0, you can now access $page->getFilename() or $page->getPath(), which you could check via a helper method in config.php.

You could also add a variable in the YAML front matter for a page, something like:

---
section: about
---

...and check the value of $page->section instead of using the filename or path.

from jigsaw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.