Navigationspunkt der aktiven Seite verlinken

Aus Contao Community Documentation


betrifft
Contao Version 2.9

Standardmäßig wird in der Navigation der Navigationslink der aktuellen Seite nicht verlinkt. Hier wird gezeigt, wie das Template angepasst werden kann, damit der Link in der Navigation aktiv bleibt.

Änderung des Templates in Contao 2.9

Kopie des Orginaltemplates erstellen

  • unter Layout/Templates
  • Button "Neues Template"
  • das Template (Abschnitt frontend) "nav_default.tpl" auswählen


Genaue Beschreibung zum Bearbeiten eines Templates siehe Artikel Templates_bearbeiten

Template bearbeiten (in Contao 2.9)

Quelltext des Orginaltemplates (nav_default.tpl):

<ul class="<?php echo $this->level; ?>">
<?php foreach ($this->items as $item): ?>
  <?php if ($item['isActive']): ?>
    <li class="active<?php if ($item['class']): ?> <?php echo $item['class']; ?><?php endif; ?>">
      <!-- Dieses <span> soll zum Link werden: -->
      <span class="active<?php if ($item['class']): ?> <?php echo $item['class']; ?><?php endif; ?>">
        <?php echo $item['link']; ?>
      </span>
 
      <?php echo $item['subitems']; ?>
    </li>
  <?php else: ?>
    <li<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?>>
      <a href="<?php echo $item['href']; ?>" title="<?php echo $item['pageTitle'] ? $item['pageTitle'] : $item['title']; ?>"<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?><?php if ($item['accesskey'] != ''): ?> accesskey="<?php echo $item['accesskey']; ?>"<?php endif; ?><?php if ($item['tabindex']): ?> tabindex="<?php echo $item['tabindex']; ?>"<?php endif; ?><?php if ($item['nofollow']): ?> rel="nofollow"<?php endif; ?><?php echo $item['target']; ?>>
        <?php echo $item['link']; ?>
      </a>
      <?php echo $item['subitems']; ?>
    </li>
  <?php endif; ?>
<?php endforeach; ?>
</ul>

Dabei wird die span-Zeile ausgetauscht:

<span class="active<?php if ($item['class']): ?> <?php echo $item['class']; ?><?php endif; ?>">
  <?php echo $item['link']; ?>
</span>

gegen

<a href="<?php echo $item['href']; ?>" title="<?php echo $item['pageTitle'] ? $item['pageTitle'] : $item['title']; ?>"<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?><?php if ($item['accesskey'] != ''): ?> accesskey="<?php echo $item['accesskey']; ?>"<?php endif; ?><?php if ($item['tabindex']): ?> tabindex="<?php echo $item['tabindex']; ?>"<?php endif; ?><?php if ($item['nofollow']): ?> rel="nofollow"<?php endif; ?><?php echo $item['target']; ?>>
  <?php echo $item['link']; ?>
</a>

Ergebnis (nav_default.tpl):

<ul class="<?php echo $this->level; ?>">
 
<?php foreach ($this->items as $item): ?>
  <?php if ($item['isActive']): ?>
  <li class="active<?php if ($item['class']): ?> <?php echo $item['class']; ?><?php endif; ?>">
 
    <!-- Hier haben wir es geaendert -->
    <a href="<?php echo $item['href']; ?>" title="<?php echo $item['pageTitle'] ? $item['pageTitle'] : $item['title']; ?>"<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?><?php if ($item['accesskey'] != ''): ?> accesskey="<?php echo $item['accesskey']; ?>"<?php endif; ?><?php if ($item['tabindex']): ?> tabindex="<?php echo $item['tabindex']; ?>"<?php endif; ?><?php if ($item['nofollow']): ?> rel="nofollow"<?php endif; ?><?php echo $item['target']; ?>>
      <?php echo $item['link']; ?>
    </a>
 
    <?php echo $item['subitems']; ?>
  </li>
  <?php else: ?>
 
  <li<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?>>
    <a href="<?php echo $item['href']; ?>" title="<?php echo $item['pageTitle'] ? $item['pageTitle'] : $item['title']; ?>"<?php if ($item['class']): ?> class="<?php echo $item['class']; ?>"<?php endif; ?><?php if ($item['accesskey'] != ''): ?> accesskey="<?php echo $item['accesskey']; ?>"<?php endif; ?><?php if ($item['tabindex']): ?> tabindex="<?php echo $item['tabindex']; ?>"<?php endif; ?><?php if ($item['nofollow']): ?> rel="nofollow"<?php endif; ?><?php echo $item['target']; ?>>
      <?php echo $item['link']; ?>
    </a>
    <?php echo $item['subitems']; ?>
  </li>
 
  <?php endif; ?>
<?php endforeach; ?>
</ul>

Änderung des Templates in Contao 2.7

siehe http://jooon.de/node/346

Ansichten
Meine Werkzeuge

Contao Community Documentation

Chuck Norris programmiert kein PHP, er diktiert das Ergebnis. Den Rest macht der Editor aus Angst.

Stefan Lindecke
Navigation
Verstehen
Verwenden
Entwickeln
Verschiedenes
Werkzeuge