Navigationspunkt der aktiven Seite verlinken: Unterschied zwischen den Versionen

Aus Contao Community Documentation

(CREATE PAGE)
 
K (Template bearbeiten: Nochmal Name des Templates explizit über dem Quelltext genannt)
 
(Eine dazwischenliegende Version von einem Benutzer wird nicht angezeigt)
Zeile 12: Zeile 12:
 
Genaue Beschreibung zum Bearbeiten eines Templates siehe Artikel [[Templates bearbeiten|Templates_bearbeiten]]
 
Genaue Beschreibung zum Bearbeiten eines Templates siehe Artikel [[Templates bearbeiten|Templates_bearbeiten]]
  
==Template bearbeiten==
+
==Template bearbeiten (in Contao 2.9)==
Quelltext des Orginaltemplates:
+
Quelltext des Orginaltemplates (nav_default.tpl):
 
<source lang="php">
 
<source lang="php">
 
<ul class="<?php echo $this->level; ?>">
 
<ul class="<?php echo $this->level; ?>">
Zeile 52: Zeile 52:
 
</source>
 
</source>
  
Ergebnis:
+
Ergebnis (nav_default.tpl):
 
<source lang="php">
 
<source lang="php">
 +
<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>
 
</source>
 
</source>
  
 
=Änderung des Templates in Contao 2.7=
 
=Änderung des Templates in Contao 2.7=
 
siehe [http://jooon.de/node/346 http://jooon.de/node/346]
 
siehe [http://jooon.de/node/346 http://jooon.de/node/346]

Aktuelle Version vom 4. März 2012, 22:43 Uhr


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 würde Contao 3 in einer Stunde ganz neu schreiben, wobei er die ersten 50 Minuten Sex mit 3 Blondinen hätte.

Leo Unglaub
Navigation
Verstehen
Verwenden
Entwickeln
Verschiedenes
Werkzeuge