Skip to content
Code-Schnipsel Gruppen Projekte
Commit a0904198 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

feat: #123 - Its possible to include bricks into the content now

Übergeordneter 1a3c83e8
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -4,4 +4,5 @@
<event on="onSmartyInit" fire="\QUI\Bricks\Events::onSmartyInit"/>
<event on="onPackageSetup" fire="\QUI\Bricks\Events::onPackageSetup"/>
<event on="onDeleteProject" fire="\QUI\Bricks\Events::onDeleteProject"/>
<event on="onOutputParseEnd" fire="\QUI\Bricks\Events::onOutputParseEnd"/>
</events>
......@@ -301,4 +301,59 @@ public static function onPackageSetup(QUI\Package\Package $Package)
QUI\System\Log::writeException($Exception);
}
}
//region output filter
/**
* @param $content
*/
public static function onOutputParseEnd(&$content)
{
if (\strpos($content, '{{brick id=') === false) {
return;
}
// search css files
$content = \preg_replace_callback(
'#{{brick ([^}}]*)}}#',
['QUI\Bricks\Events', "outputParsing"],
$content
);
}
/**
* @param $match
*/
public static function outputParsing($match)
{
$params = $match[0];
$params = \str_replace('{{brick', '', $params);
$params = \trim($params, '}}');
$params = \trim($params);
$params = \explode(' ', $params);
$attributes = [];
foreach ($params as $param) {
$a = \explode('=', $param);
$attributes[$a[0]] = $a[1];
}
if (!isset($attributes['id'])) {
return $match[0];
}
try {
$brickId = (int)$attributes['id'];
$Brick = Manager::init()->getBrickById($brickId);
return $Brick->create();
} catch (\Exception $Exception) {
}
return $match[0];
}
//endregion
}
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren