Ankündigung

Einklappen
Keine Ankündigung bisher.

filter select ausgabe des Datums in Monat und Jahr

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • filter select ausgabe des Datums in Monat und Jahr

    Habe das customcatalog_filter_select template dahingehend umgeschrieben, daß es mir das Datum im Format Monat Jahr ausgibt. Nun aber weiß ich nicht weiter, wie ich den label wieder bekomme, dieser bleibt nun weiß, also ohne Eintrag.
    Änderung in Zeile 27 <?php echo $this->parseDate("F Y", $option['label']); ?>
    Hier mein Template:
    Code:
    <?php
    /**
     * Select/Radio-Button filter template
     */
    ?>
    
    <?php if($this->radio): ?>
    <div <?php echo $this->cssID; ?> class="widget <?php echo $this->class; ?> block">
    <fieldset class="radio_container">
        <?php if($this->label): ?><legend><?php echo $this->label; ?></legend><?php endif; ?>
        <?php foreach($this->options as $option): ?>
        <div>
            <input type="radio" class="radio" name="<?php echo $this->name; ?>" value="<?php echo $option['value']; ?>" <?php if($option['selected']):?>checked<?php endif;?> ><?php echo $option['label']; ?> <?php if($option['id']): ?>(<?php echo $this->countValue($option['value']); ?>)<?php endif; ?>
            <label id="lbl_<?php echo $option['id']; ?>" for="opt_<?php echo $option['id']; ?>"><?php echo $option['label']; ?></label>
        </div>
        <?php endforeach; ?>
        <?php if($this->description): ?><div class="description"><?php echo $this->description; ?></div><?php endif; ?>
    </fieldset>
    <?php if($this->description): ?><div class="description"><?php echo $this->description; ?></div><?php endif; ?>    
    </div>
    <?php else: ?>
    <div <?php echo $this->cssID; ?> class="widget <?php echo $this->class; ?> block">
    <fieldset class="select_container">
        <?php if($this->label): ?><legend><?php echo $this->label; ?></legend><?php endif; ?>
        <select name="<?php echo $this->name; ?>">
        <?php foreach($this->options as $option): ?>
        <option value="<?php echo $option['value']; ?>"<?php if($option['selected']):?>selected<?php endif;?>>
        <?php echo $this->parseDate("F Y", $option['label']); ?> <?php if($option['id']): ?>(<?php echo $this->countValue($option['value']); ?>)<?php endif; ?>
        </option>
        <?php endforeach; ?>
        </select>
    </fieldset>
    <?php if($this->description): ?><div class="description"><?php echo $this->description; ?></div><?php endif; ?>    
    </div>
    <?php endif; ?>
    Vielen Dank für Eure Mühe.

  • #2
    Meines Erachtens darf das parseDate nicht mit dem Wert des Labels erfolgen (das ist in der Regel kein Zeitstempelwert), sondern muss über value laufen bzw. muss vorher ein sauberer Unix-Zeitstempel erzeugt werden.

    - 1. sauberen Unixzeitstempel erzeugen
    - 2. parseDate mit diesem Zeitstempel ausführen.
    http://www.premium-contao-themes.com

    Kommentar


    • #3
      Danke Tim, für Deine rasche Reaktion und Hilfe. Das Feld reise_beginn ist vom Typ timestamp. Meine Frage ist nun, wie ich den label trennen kann. Vielleicht kannst Du mir das machen? Auftrag an Euch. Danke.

      Kommentar


      • #4
        Du machst das bereits richtig. Du musst parseDate nur korrekt füttern.

        Wenn value hier die timestamps trägt (Quell-Attribut ist z.B. ein Datumsfeld) geht es so:

        (die Leere Option auf Position 0 überspringen)
        Code:
        [COLOR=#333333][FONT=Monaco][SIZE=11px][COLOR=#878787]<?php[/COLOR]
          [COLOR=#8735a5]$label[/COLOR] [COLOR=#000000]=[/COLOR] [COLOR=#8735a5]$option[/COLOR][[COLOR=#dd2400]'label'[/COLOR]];
          [COLOR=#0045aa]if[/COLOR][COLOR=#000000]([/COLOR] [COLOR=#8735a5]$i[/COLOR] [COLOR=#000000]>[/COLOR] [COLOR=#007ab7]0[/COLOR] [COLOR=#000000])[/COLOR]
          [COLOR=#000000]{[/COLOR]
          [COLOR=#8735a5]$label[/COLOR] [COLOR=#000000]=[/COLOR] \Contao\Date[COLOR=#000000]::[/COLOR][COLOR=#3f6e7d]parse[/COLOR]([COLOR=#dd2400]'F Y'[/COLOR],[COLOR=#8735a5]$option[/COLOR][[COLOR=#dd2400]'value'[/COLOR]]);
          [COLOR=#000000]}[/COLOR]
          [COLOR=#878787]?[/COLOR][COLOR=#878787]>[/COLOR]
          [COLOR=#0045aa]<option [/COLOR][COLOR=#007ab7]value=[/COLOR][COLOR=#5d8f00]"[/COLOR][COLOR=#878787]<?php [/COLOR][COLOR=#0045aa]echo [/COLOR][COLOR=#8735a5]$option[/COLOR][COLOR=#000000][[/COLOR][COLOR=#dd2400]'value'[/COLOR][COLOR=#000000]];[/COLOR][COLOR=#878787]?[/COLOR][COLOR=#878787]>[/COLOR][COLOR=#5d8f00]"[/COLOR][COLOR=#878787]<?php [/COLOR][COLOR=#0045aa]if[/COLOR][COLOR=#000000]([/COLOR][COLOR=#8735a5]$option[/COLOR][COLOR=#007ab7][[/COLOR][COLOR=#5d8f00]'selected'[/COLOR][COLOR=#007ab7]][/COLOR][COLOR=#000000]):[/COLOR][COLOR=#878787]?[/COLOR][COLOR=#878787]>[/COLOR][COLOR=#007ab7]selected[/COLOR][COLOR=#878787]<?php [/COLOR][COLOR=#0045aa]endif[/COLOR][COLOR=#000000];[/COLOR][COLOR=#878787]?[/COLOR][COLOR=#878787]>[/COLOR][COLOR=#0045aa]>[/COLOR][COLOR=#878787]<?=[/COLOR] [COLOR=#8735a5]$label[/COLOR]; [COLOR=#878787]?[/COLOR][COLOR=#878787]>[/COLOR] [COLOR=#878787]<?php[/COLOR] [COLOR=#0045aa]if[/COLOR][COLOR=#000000]([/COLOR][COLOR=#8735a5]$option[/COLOR][[COLOR=#dd2400]'id'[/COLOR]][COLOR=#000000])[/COLOR]: [COLOR=#878787]?[/COLOR][COLOR=#878787]>[/COLOR]([COLOR=#878787]<?php[/COLOR] [COLOR=#0045aa]echo[/COLOR] [COLOR=#8735a5]$this[/COLOR][COLOR=#000000]->[/COLOR][COLOR=#3f6e7d]countValue[/COLOR]([COLOR=#8735a5]$option[/COLOR][[COLOR=#dd2400]'value'[/COLOR]]); [COLOR=#878787]?[/COLOR][COLOR=#878787]>[/COLOR])[COLOR=#878787]<?php[/COLOR] [COLOR=#0045aa]endif[/COLOR]; [COLOR=#878787]?[/COLOR][COLOR=#878787]>[/COLOR][COLOR=#0045aa]</option>[/COLOR][/SIZE][/FONT][/COLOR]
        Zuletzt geändert von Tim; 11.06.2021, 09:48.
        http://www.premium-contao-themes.com

        Kommentar


        • #5
          Danke Tim. Jetzt wird mir zwar das zurücksetzen des Filters angezeigt, jedoch bekomme ich im label nur den timestamp angezeigt. Habe schon alles probiert, auch mit date. Währest Du so nett und könntest Du mir ein weiteres mal helfen, Danke.

          Code:
          <div <?php echo $this->cssID; ?> class="widget <?php echo $this->class; ?> block">
          <fieldset class="select_container">
              <?php if($this->label): ?><legend><?php echo $this->label; ?></legend><?php endif; ?>
              <select name="<?php echo $this->name; ?>">
              <?php foreach($this->options as $option):
            $label = $option['label'];
            if( $i > 0 )
            {
            //$label = \Contao\Date::parse('F Y',$option['label']);
            //$label = parseDate("F Y", $option['label']);
            $label = date("F Y", $option['value']);
            }
            ?>
            <option value="<?php echo $option['value'];?>"<?php if($option['selected']):?>selected<?php endif;?>>
            <?php echo $option['label']; ?> <?php if($option['id']): ?>(<?php echo $this->countValue($option['value']); ?>)
            <?php endif; ?>
            </option>
              <?php endforeach; ?>
              </select>
          </fieldset>
          <?php if($this->description): ?><div class="description"><?php echo $this->description; ?></div><?php endif; ?>    
          </div>
          <?php endif; ?> [ATTACH=CONFIG]n22679[/ATTACH]

          Kommentar


          • #6
            Du musst noch richtig copy and paste machen.

            Du ersetzt $option['label'] nicht mit dem frisch erstellten $label
            http://www.premium-contao-themes.com

            Kommentar


            • #7
              Danke Dir. Habe es nun ersetzt. Jedoch werden über $label immer noch nur die Timestamps angezeigt. Es scheint so als würde in der Schleife unter $label die Werte nicht in das Format Monat Jahr umgewandelt. Sorry.

              Kommentar


              • #8
                Bitte check mal deinen Code gegen meinen oder mal richtig heraus kopieren

                Ich nutzen "value" als Quelle, nicht "label" und ersetze dann "label" mit der geänderten $label Variable im <option> Element.

                Ausgabe ist dann (basierend auf Datums-Feldern)

                Anbei das Template.
                Klicke auf die Grafik für eine vergrößerte Ansicht

Name: screenshot_7086.jpg
Ansichten: 52
Größe: 26,2 KB
ID: 22688
                http://www.premium-contao-themes.com

                Kommentar


                • #9
                  Danke, funktioniert. Kannst Du mir noch sagen wie ich den "ersten Eintrag" selbst einen "Namen" geben kann? Also zB. für Reisebeginn filtern möchte ich Alle Reisen anzeigen.

                  Kommentar


                  • #10
                    Entweder auch direkt im Template, es ist ja bereits eine Weiche drin für Nummer > 1, der Erste Eintrag wäre quasi $i == 0, oder global über die Sprachvariablen: https://forum.premium-contao-themes....en-%C3%A4ndern

                    -> _firstOption
                    http://www.premium-contao-themes.com

                    Kommentar


                    • #11
                      Danke herzlichst.

                      Kommentar

                      Lädt...
                      X