Neu Smarty Variable als class

manuel767

Aktives Mitglied
10. Oktober 2016
87
6
Hallo Zusammen,

Ich habe geplant für die Variationsauswahl eine Hilfefunktion einzubauen (Siehe Bild), dazu möchte ich bei der variations.tpl jedem Variationsnamen eine class mit dem Namen der Variation hinzufügen. variation_{$Variation->cName}

HTML:
<div class="freifeld__label variation_{$Variation->cName}">{$Variation->cName}{if $Variation->cTyp === 'IMGSWATCHES'} <span class="swatches-selected text-muted" data-id="{$Variation->kEigenschaft}"></span>{/if}</div>

Dies funktioniert so auch perfekt. Ich hab nur das Problem, wenn der Variationsname Umlaute (ö,ä,ß) enthält, da ich dann die class nicht per jquery manipulation erweitern kann ....

Hat jemand einen Tipp wie ich die Smarty Variable so einbauen kann, dass alle Umlaute ersetzt werden?

Code:
variation_{$Variation->cName}

Vielen Dank
 

Anhänge

  • Bildschirmfoto 2021-02-14 um 11.17.07.png
    Bildschirmfoto 2021-02-14 um 11.17.07.png
    22,1 KB · Aufrufe: 20

Xantiva

Sehr aktives Mitglied
28. August 2016
1.795
316
Düsseldorf
Welchen Shop hast Du? Ich habe damals im 4'er ein Child-Template erstellt. Dort im Unterordner /php eine Datei functions.php angelegt:

PHP:
<?php
require_once $smarty->get_template_vars('parent_template_path').'php/functions.php';

$smarty->registerPlugin('modifier', 'escapeUmlaute', 'escapeUmlaute');

/**
 *
 * @param type $string
 */
function escapeUmlaute($string)
{
    $string = str_replace("ä", "ae", $string);
    $string = str_replace("ü", "ue", $string);
    $string = str_replace("ö", "oe", $string);
    $string = str_replace("Ä", "Ae", $string);
    $string = str_replace("Ü", "Ue", $string);
    $string = str_replace("Ö", "Oe", $string);
    $string = str_replace("ß", "ss", $string);
    $string = str_replace("´", "", $string);
    return $string;
}

Dann kannst Du es so einsetzen:

PHP:
variation_{$Variation->cName | escapeUmlaute}

Ohne Gewähr, ungetestet!
 

manuel767

Aktives Mitglied
10. Oktober 2016
87
6
Welchen Shop hast Du? Ich habe damals im 4'er ein Child-Template erstellt. Dort im Unterordner /php eine Datei functions.php angelegt:

PHP:
<?php
require_once $smarty->get_template_vars('parent_template_path').'php/functions.php';

$smarty->registerPlugin('modifier', 'escapeUmlaute', 'escapeUmlaute');

/**
*
* @param type $string
*/
function escapeUmlaute($string)
{
    $string = str_replace("ä", "ae", $string);
    $string = str_replace("ü", "ue", $string);
    $string = str_replace("ö", "oe", $string);
    $string = str_replace("Ä", "Ae", $string);
    $string = str_replace("Ü", "Ue", $string);
    $string = str_replace("Ö", "Oe", $string);
    $string = str_replace("ß", "ss", $string);
    $string = str_replace("´", "", $string);
    return $string;
}

Dann kannst Du es so einsetzen:

PHP:
variation_{$Variation->cName | escapeUmlaute}

Ohne Gewähr, ungetestet!

Vielen Dank. Hab es jetzt mal so gelöst! Werde morgen deine Variante einbauen.

Code:
{$Variation->cName|replace:'ö':'oe'|replace:'ß':'ss'|replace:'ä':'ae'}

Vielen Dank
 

Ähnliche Themen