TryGhost / Ghost

Independent technology for modern publishing, memberships, subscriptions and newsletters.
https://ghost.org
MIT License
47.68k stars 10.41k forks source link

@blog globals not working in navigation/pagination special partials #5024

Closed vezaynk closed 9 years ago

vezaynk commented 9 years ago

{{navigation}} seems to be having strange issues.

I have some code in a partial called navigation.hbs which I include in default.hbs.

The affected code is the following:

<ul class="nav navbar-nav">
      {{#foreach navigation}}
    <li class="nav-{{slug}}{{#if current}} active{{/if}}" role="presentation"><a href="{{url absolute="true"}}">{{label}}</a></li>
    {{/foreach}}

      </ul>

Full code:

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="{{@blog.url}}">{{@blog.title}}</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
      {{#foreach navigation}}
    <li class="nav-{{slug}}{{#if current}} active{{/if}}" role="presentation"><a href="{{url absolute="true"}}">{{label}}</a></li>
    {{/foreach}}

      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

Issue 1: I cannot use global variables.

This line:

<a class="navbar-brand" href="{{@blog.url}}">{{@blog.title}}</a>

Gives the following:

<a class="navbar-brand" href=""></a>

Issue 2:

I then tried replacing

{{navigation}}

with the actual code I had. The issue was fixed but a new one appeared; The following code did not return anything:

 {{#foreach navigation}}
    <li class="nav-{{slug}}{{#if current}} active{{/if}}" role="presentation"><a href="{{url absolute="true"}}">{{label}}</a></li>
    {{/foreach}}

You can try it by yourself, the theme I am working on is here: https://github.com/viruzx/Basic-Plus-Ghost-Theme

vezaynk commented 9 years ago

I figured out a really ugly workaround but it works so you may take your time.

What I did was I put the first half of the code into default.hbs.

dbalders commented 9 years ago

For some reason, the attributes in the default Casper navigation show up, even if I paste Casper's navigation code into @viruzx's theme, but this bug still does seem to exist. If I add <p>{{@blog.title}}</p> or other blog attributes to the navigation.hbs of casper, it shows up blank. So, I do believe this is a bug, I just cannot figure out why it works for default casper code, and not other custom code.