Ankündigung

Einklappen
Keine Ankündigung bisher.

CustomCatalog Select-Filter-Template alphabetisch sortiert

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

  • CustomCatalog Select-Filter-Template alphabetisch sortiert

    Hi Leute,
    anbei ein kleines Template für die Filterausgabe als Select-/Radio-Button, alphabetisch sortiert.

    Code:
      <?php
      $arrOptions = $this->options;
      // leere option abgreifen
      $arrBlankOption = $arrOptions[0];
      // leere option entfernen
      unset($arrOptions[0]);
        $tmp = array();
      foreach($arrOptions as $option)
      {
          $k = standardize($option['label']);
          $tmp[$k] = $option;
      }
      ksort($tmp);
      $arrOptions = $tmp;
      unset($tmp);
         // leere Option wieder einsetzen
      array_insert($arrOptions,0,array($arrBlankOption));
      ?>
        <?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($arrOptions 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($arrOptions as $option): ?>
          <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; ?>
    Angehängte Dateien
    http://www.premium-contao-themes.com

  • #2
    customcatalog_filter_counstryselect.html5

    Für die Länderausgabe kann der Schlüsselwert über die Ländernamen gesetzt werden und damit sortiert werden.
    Der Rest des Templates ist identisch

    Code:
      
      <?php
      $arrCountries = \Contao\System::getCountries();
        $arrOptions = $this->options;
      // leere option abgreifen
      $arrBlankOption = $arrOptions[0];
      // leere option entfernen
      unset($arrOptions[0]);
      $tmp = array();
      foreach($arrOptions as $option)
      {
    $search = array("Ä","ä","Ö","ö","Ü","ü","ß","-");  
    $replace = array("Ae","ae","Oe","oe","Ue","ue","ss"," ");
      $k = str_replace($search,$replace, standardize( $arrCountries[$option['value']] ) );
     
       $tmp[$k] = $option;
      }
      ksort($tmp);
      $arrOptions = $tmp;
      unset($tmp);
      // leere Option wieder einsetzen
      array_insert($arrOptions,0,array($arrBlankOption));
      ?>
    Angehängte Dateien
    Zuletzt geändert von Tim; 08.06.2021, 09:18.
    http://www.premium-contao-themes.com

    Kommentar


    • #3
      Tags (Checkboxes) sortiert.

      customcatalog_filter_tags_sorted.html5

      Code:
        <?php
          use Contao\PCT_TagsModel;
        use Contao\StringUtil;
          $arrOptions = $this->options;
        // leere option abgreifen
        $arrBlankOption = $arrOptions[0];
        // leere option entfernen
        unset($arrOptions[0]);
        $tmp = array();
        foreach($arrOptions as $option)
        {
        $objTag = PCT_TagsModel::findById($option['value']);
        $search = array("Ä","ä","Ö","ö","Ü","ü","ß","-");
        $replace = array("Ae","ae","Oe","oe","Ue","ue","ss"," ");
        $k = str_replace($search,$replace, StringUtil::standardize( $objTag->title ) );
        $tmp[$k] = $option;
        }
        krsort($tmp);
        $arrOptions = $tmp;
          unset($tmp);
        // leere Option wieder einsetzen
        array_insert($arrOptions,0,array($arrBlankOption));
        ?>
          <div <?php echo $this->cssID; ?> class="widget <?php echo $this->class; ?> block">
        <fieldset class="checkbox_container">
        <?php if($this->label): ?><legend><?php echo $this->label; ?></legend><?php endif; ?>
        <?php foreach($arrOptions as $option): ?>
        <div class="checkbox_container <?= StringUtil::standardize($option['value']); ?>">
        <label class="label"><?php echo $option['label']; ?> <?php if($option['id']): ?>(<?php echo $this->countValue($option['value']); ?>)<?php endif; ?></label>
        <input <?php if($option['id']): ?>id="<?php echo $option['id']; ?>"<?php endif; ?> type="checkbox" name="<?php echo $option['name']; ?>[]" value="<?php echo $option['value']; ?>" <?php if($option['selected']):?>checked<?php endif;?>>
        </div>
        <?php endforeach; ?>
        </fieldset>
        <?php if($this->description): ?><div class="description"><?php echo $this->description; ?></div><?php endif; ?>
        </div>
      Angehängte Dateien
      http://www.premium-contao-themes.com

      Kommentar

      Lädt...
      X