Hallo,
ich möchte beim Produkttitel und beim Teasertext nur eine bestimmte Anzahl von Zeichen zulassen und dann ein "..." anfügen.
Wie kann ich dies für die Produktliste umsetzen?
Danke
Grüße
Matu
Hallo,
ich möchte beim Produkttitel und beim Teasertext nur eine bestimmte Anzahl von Zeichen zulassen und dann ein "..." anfügen.
Wie kann ich dies für die Produktliste umsetzen?
Danke
Grüße
Matu
Viele Grüße aus Köln
Matu
Das kannst du einfach im Listen Template machen.
Benutze dazu einfach die PHP Funktion substr().
Hab leider grad keine Zeit die "echten" Variablen rauszusuchenPHP-Code:
echo substr ( $deinteaser , 0, 80 ) . "...";
Gruß
Nikolas
Oder verwende die durch das Contao-Framework bereitgestellte Methode "substr" aus der "String"-Klasse.
Vorteil: Keine harte Trennung der Wörter!
Danke, das ging flott !
Jetzt müsste ich nur warten, bis mir jemand einen passenden Code-Schnipsel postet.
Bin kein Programmierer...
Viele Grüße aus Köln
Matu
Welches Template kommt denn bei Dir für die Produktliste zum Einsatz?
Es ist das iso_list_default.html5.
Viele Grüße aus Köln
Matu
Also das Template hier: https://github.com/isotope/core/blob..._default.html5
Versuch mal die folgenden Änderungen:
Zeile 6:
Zeile 12:PHP-Code:
<h3><a href="<?php echo $this->href_reader; ?>" title="<?php echo $this->label_detail; ?>"><?php echo String::substr($this->name, 100, ' …'); ?></a></h3>
Alles ungetestet.PHP-Code:
<div class="teaser"><?php echo String::substr($this->teaser, 300, ' …'); ?></div><?php endif; ?>
Geht leider beides nicht.
1. Es kommt ein Runtime Error im Frontend, dort wor die h3 steht
2. Komplett weiße Seite mit FehlerCode:Parse error: syntax error, unexpected T_ENDIF in /var/www/html/web122/html/templates/iso_list_default.html5 on line 18
Viele Grüße aus Köln
Matu
Kannst Du bitte Dein geändertes Template hier posten?
Ah und noch was: Welche Contao-Version verwendest Du?
Geändert von xchs (23.07.2013 um 20:10 Uhr)
Code:<form action="<?php echo $this->action; ?>" id="<?php echo $this->formId; ?>" name="iso<?php echo rand(); ?>" method="post" enctype="<?php echo $this->enctype; ?>"> <div class="formbody"> <input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formSubmit; ?>"> <input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}"> <h3><a href="<?php echo $this->href_reader; ?>" title="<?php echo $this->label_detail; ?>"><?php echo String::substr($this->name, 100, ' …'); ?></a></h3> <?php echo $this->images->generateMainImage('thumbnail'); ?> <?php if ($this->sku): ?> <div class="sku"><?php echo $this->sku; ?></div><?php endif; if ($this->teaser): ?> <div class="teaser"><?php echo String::substr($this->teaser, 300, ' …'); ?></div><?php endif; ?> <div class="price"><?php echo $this->price; ?></div><?php if($this->baseprice): ?> <div class="baseprice"><?php echo $this->baseprice; ?></div><?php endif; ?> <div class="details"><a href="<?php echo $this->href_reader; ?>" title="<?php echo $this->label_detail; ?>"><?php echo $this->label_detail; ?></a></div> <?php if($this->buttons): ?> <div class="submit_container"> <!-- START: Adding special mark --> <?php $arrSpecialMark = deserialize($this->raw['specialmark']); ?> <?php if (in_array("new", $arrSpecialMark)): ?> <img src="tl_files/aufbau/basics/shop_new.png" /> <?php endif; ?> <?php if (in_array("rebate", $arrSpecialMark)): ?> <img src="tl_files/aufbau/basics/shop_sale.png" /> <?php endif; ?> <!-- END: Adding special mark --> <?php if($this->hasOptions): ?> <div class="options"> <?php foreach( $this->options as $arrOption ): echo $arrOption['html']; endforeach; ?> </div> <?php endif; ?> <?php if ($this->useQuantity): ?> <div class="quantity_container"> <label for="quantity_requested_<?php echo $this->raw['id']; ?>"><?php echo $this->quantityLabel; ?>:</label> <input type="text" class="text" id="quantity_requested_<?php echo $this->raw['id']; ?>" name="quantity_requested" value="<?php echo $this->quantity_requested; ?>" maxlength="10" onblur="if (this.value=='') { this.value='1'; }" onfocus="if (this.value=='1') { this.value=''; }"> </div> <?php endif; ?> <?php foreach( $this->buttons as $name => $button ): ?> <input type="submit" class="submit <?php echo $name; ?>" name="<?php echo $name; ?>" value="<?php echo $button['label']; ?>"> <?php endforeach; ?> </div> <?php endif; ?> </div> </form>
Viele Grüße aus Köln
Matu
Hatte oben im letzten Beitrag noch was hinzugefügt: Welche Contao-Version verwendest Du?
Für Contao 2.x versuche mal dieses Template:
Hast Du – außer den beiden von mir weiter oben genannten – noch weitere Änderungen am Template vorgenommen?PHP-Code:
<form action="<?php echo $this->action; ?>" id="<?php echo $this->formId; ?>" name="iso<?php echo rand(); ?>" method="post" enctype="<?php echo $this->enctype; ?>">
<div class="formbody">
<input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formSubmit; ?>">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
<?php $this->import('String'); ?>
<h3><a href="<?php echo $this->href_reader; ?>" title="<?php echo $this->label_detail; ?>"><?php echo $this->String->substr($this->name, 100, ' …'); ?></a></h3>
<?php echo $this->images->generateMainImage('thumbnail'); ?>
<?php if ($this->sku): ?>
<div class="sku"><?php echo $this->sku; ?></div><?php endif; if ($this->teaser): ?>
<div class="teaser"><?php echo $this->String->substr($this->teaser, 300, ' …'); ?></div><?php endif; ?>
<div class="price"><?php echo $this->price; ?></div><?php if($this->baseprice): ?>
<div class="baseprice"><?php echo $this->baseprice; ?></div><?php endif; ?>
<div class="details"><a href="<?php echo $this->href_reader; ?>" title="<?php echo $this->label_detail; ?>"><?php echo $this->label_detail; ?></a></div>
<?php if($this->buttons): ?>
<div class="submit_container">
<!-- START: Adding special mark -->
<?php $arrSpecialMark = deserialize($this->raw['specialmark']); ?>
<?php if (in_array("new", $arrSpecialMark)): ?>
<img src="tl_files/aufbau/basics/shop_new.png" />
<?php endif; ?>
<?php if (in_array("rebate", $arrSpecialMark)): ?>
<img src="tl_files/aufbau/basics/shop_sale.png" />
<?php endif; ?>
<!-- END: Adding special mark -->
<?php if($this->hasOptions): ?>
<div class="options">
<?php foreach( $this->options as $arrOption ): echo $arrOption['html']; endforeach; ?>
</div>
<?php endif; ?>
<?php if ($this->useQuantity): ?>
<div class="quantity_container">
<label for="quantity_requested_<?php echo $this->raw['id']; ?>"><?php echo $this->quantityLabel; ?>:</label> <input type="text" class="text" id="quantity_requested_<?php echo $this->raw['id']; ?>" name="quantity_requested" value="<?php echo $this->quantity_requested; ?>" maxlength="10" onblur="if (this.value=='') { this.value='1'; }" onfocus="if (this.value=='1') { this.value=''; }">
</div>
<?php endif; ?>
<?php foreach( $this->buttons as $name => $button ): ?>
<input type="submit" class="submit <?php echo $name; ?>" name="<?php echo $name; ?>" value="<?php echo $button['label']; ?>">
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</form>
Geändert von xchs (23.07.2013 um 20:26 Uhr)
Ich verwende Contao 2.11.6 und Isotope 1.4.4.
Diesen Block habe ich noch ins Template gesetzt (Ausgabe in der Liste als Neu oder Sale):
Code:<!-- START: Adding special mark --> <?php $arrSpecialMark = deserialize($this->raw['specialmark']); ?> <?php if (in_array("new", $arrSpecialMark)): ?> <img src="tl_files/aufbau/basics/shop_new.png" /> <?php endif; ?> <?php if (in_array("rebate", $arrSpecialMark)): ?> <img src="tl_files/aufbau/basics/shop_sale.png" /> <?php endif; ?> <!-- END: Adding special mark -->
Viele Grüße aus Köln
Matu
Super, jetzt funzen beide Änderunegn, vielen Dank !
Viele Grüße aus Köln
Matu
Funktioniert es auch noch, wenn Du die Zeile 5
entfernst?PHP-Code:
<?php $this->import('String'); ?>
Falls ja, steht die "String"-Klasse bereits zur Verfügung und braucht demnach nicht nochmals extra importiert zu werden.
Nein, dann geht es nicht mehr...
Viele Grüße aus Köln
Matu
Okay, alles klar. Dann muss die Zeile <?php $this->import('String'); ?> also wieder ins Template rein.
Die Anzahl der Zeichen für die Überschrift ("100") bzw. den Teaser ("300") kannst Du natürlich so anpassen wie Du es gerne hättest. Aber das wusstest Du bestimmt schon.
Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
Lesezeichen