Modify

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#2458 closed Neues Feature (fixed)

IDs und Klassen auf body-Level zur Vereinfachung von Selektoren für CSS

Reported by: noRiddle Owned by: Markus Rehm
Priority: normal Milestone: modified-shop-2.0.8.0
Component: Shop Version: 2.0.7.2
Keywords: Cc:
Blocked By: Blocking:

Description

Wie ich vor einiger Zeit an diversen Stellen im Forum bereits vorgeschlagen habe wären IDs und Klassen auf body-Level sinnvoll, um Selektoren auf Seiten-Level zu erhalten mit welchen man besser bestimmte Bereiche ansprechen kann.

Beispiel für die /includes/header.php:

<?php

$PATH_ID = '';
$PATH_CLASS = '';
$ID_PATH_ID = '';
$CLASS_PATH_CLASS = '';
if (strpos($PHP_SELF, 'index') && !isset($_GET['cPath']) && !isset($_GET['manufacturers_id'])) {
    $PATH_CLASS = 'start';
    //$PATH_ID = 'start';
} elseif (isset($_GET['cPath'])) {
    $cP = preg_replace("#[^0-9_]#", '', $_GET['cPath']);
    $PATH_CLASS = 'cat';
    $PATH_ID = 'cat-'.$cP;
} elseif (isset($_GET['manufacturers_id']) && !strpos($PHP_SELF, 'search_result')) {
    $mID = (int)$_GET['manufacturers_id'];
    $PATH_CLASS = 'man';
    $PATH_ID = 'man-'.$mID;
} elseif (strpos($PHP_SELF, 'product_info')) {
    $pID = (int)$_GET['products_id'];
    $PATH_CLASS = 'prod';
    $PATH_ID = 'prod-'.$pID;
} elseif (strpos($PHP_SELF, 'search_result')) {
    $sr = 'sr';
    $PATH_CLASS = $sr;
    //$PATH_ID = $sr;
} elseif (isset($_GET['coID'])) {
    $coID = (int)$_GET['coID'];
    $PATH_CLASS = 'cont';
    $PATH_ID = 'cont-'.$coID;
} elseif (strpos($PHP_SELF, 'account')) {
    $PATH_CLASS = 'acco';
} elseif (strpos($PHP_SELF, 'shopping')) {
    $PATH_CLASS = 'shopp';
} elseif (strpos($PHP_SELF, 'checkout_shipping')) {
    $PATH_CLASS = 'ch-shipp';
} elseif (strpos($PHP_SELF, 'checkout_payment')) {
    $PATH_CLASS = 'ch-pay';
} elseif (strpos($PHP_SELF, 'checkout_confirmation')) {
    $PATH_CLASS = 'ch-conf';
}

$ID_PATH_ID = $PATH_ID != '' ? ' id="'.$PATH_ID.'"' : '';
$CLASS_PATH_CLASS = $PATH_CLASS != '' ? ' class="'.$PATH_CLASS.'"' : '';
?>
<body<?php echo $ID_PATH_ID . $PATH_CLASS; ?>>

Damit kann man dann beispielsweise generell Kategorieseiten ansprechen

.cat SUBSELECTOR {
  background:#XXX
}

oder explizit

.cat-1_3 SUBSELECTOR {
  background:#YYY
}

oder die Startseite

.start SUBSELECTOR {
  background:#ZZZ
}

oder...

Gruß,
noRiddle

Attachments (0)

Change History (6)

comment:1 by Torsten Riemer, 3 years ago

Das kannst du doch bereits jetzt problemlos ohne Core-Änderungen über die auto_includes lösen:

"/includes/extra/application_bottom/body.php":

<?php
$PATH_ID = '';
$PATH_CLASS = '';
$ID_PATH_ID = '';
$CLASS_PATH_CLASS = '';
if (strpos($PHP_SELF, 'index') && !isset($_GET['cPath']) && !isset($_GET['manufacturers_id'])) {
    $PATH_CLASS = 'start';
    //$PATH_ID = 'start';
} elseif (isset($_GET['cPath'])) {
    $cP = preg_replace("#[^0-9_]#", '', $_GET['cPath']);
    $PATH_CLASS = 'cat';
    $PATH_ID = 'cat-'.$cP;
} elseif (isset($_GET['manufacturers_id']) && !strpos($PHP_SELF, 'search_result')) {
    $mID = (int)$_GET['manufacturers_id'];
    $PATH_CLASS = 'man';
    $PATH_ID = 'man-'.$mID;
} elseif (strpos($PHP_SELF, 'product_info')) {
    $pID = (int)$_GET['products_id'];
    $PATH_CLASS = 'prod';
    $PATH_ID = 'prod-'.$pID;
} elseif (strpos($PHP_SELF, 'search_result')) {
    $sr = 'sr';
    $PATH_CLASS = $sr;
    //$PATH_ID = $sr;
} elseif (isset($_GET['coID'])) {
    $coID = (int)$_GET['coID'];
    $PATH_CLASS = 'cont';
    $PATH_ID = 'cont-'.$coID;
} elseif (strpos($PHP_SELF, 'account')) {
    $PATH_CLASS = 'acco';
} elseif (strpos($PHP_SELF, 'shopping')) {
    $PATH_CLASS = 'shopp';
} elseif (strpos($PHP_SELF, 'checkout_shipping')) {
    $PATH_CLASS = 'ch-shipp';
} elseif (strpos($PHP_SELF, 'checkout_payment')) {
    $PATH_CLASS = 'ch-pay';
} elseif (strpos($PHP_SELF, 'checkout_confirmation')) {
    $PATH_CLASS = 'ch-conf';
}

//$ID_PATH_ID = $PATH_ID != '' ? ' id="'.$PATH_ID.'"' : '';
//$CLASS_PATH_CLASS = $PATH_CLASS != '' ? ' class="'.$PATH_CLASS.'"' : '';

if ($PATH_CLASS != ''){
  echo '
  <script>
  $(document).ready(function() {
    $(\'body\').attr(\'class\',\''.$PATH_CLASS.'\');
  });
  </script>';
}

if ($PATH_ID != ''){
  echo '
  <script>
  $(document).ready(function() {
    $(\'body\').attr(\'id\',\''.$PATH_ID.'\');
  });
  </script>';
}

//echo $PATH_CLASS;
?>

comment:2 by noRiddle, 3 years ago

Du wirst lachen, genau das habe ich gemacht.
Aber wäre es nicht nice das schon mittels PHP so zu haben, anstatt mit JS agieren zu müssen ?

Ist ja auch lediglich ein Vorschlag.

Gruß,
noRiddle

comment:3 by noRiddle, 3 years ago

*NACHTRAG*

...ein Vorschlag der für einige Seiten auch einfacher geht mittels basename($PHP_SELF = 'XX'), wie z.B. bei product_info.

Gruß,
noRiddle

comment:4 by Gerhard Waldemair, 3 years ago

Owner: changed from somebody to Markus Rehm
Status: newassigned

comment:5 by Gerhard Waldemair, 2 years ago

Resolution: fixed
Status: assignedclosed

Durch Einführung des Nova Templates in r15291 gefixt. Ein Umbau für das tpl_modified_responsive ist nicht geplant.

comment:6 by Torsten Riemer, 2 years ago

Wir haben dafür die Variable $display_mode eingefügt.

Modify Ticket

Action
as closed The owner will remain Markus Rehm.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.