Search code examples
spark-view-engine

Update master template from child template using Spark


I have the following nav section in my master template. I want to set the active class to the correct nav element from the child template.

<ul class="nav nav-pills pull-right">
    <li class="active"><a href="/">Home</a></li>
    <li><a href="/browser">Browse</a></li>
    <li><a href="/commision">Create</a></li>
    <li><a href="/contact">Contact</a></li>
    <li><a href="/about">About</a></li>
</ul>

Is it possible to set the active class on the correct nav option in the master template from the child template?


Solution

  • I would probably try and do this via a ViewModel property instead which can be read as the page renders, but if you're looking for a way to have a variable set by a child that the master view can see, then you can always declare and use a global for example:

    <global activeItem="Home" />
    

    can be declared in the master and then:

    <set activeItem="Contact" />
    

    in the child view.