MultiBlock Section Switcher #57
Unanswered
vixov
asked this question in
Q&A - Plugins
Replies: 1 comment
-
|
I am extending the thread: if anyone would like sorting to work with this code, please insert the following snippet according to the template: `<?php $map = [ $block = isset($map[$slug]) ? $map[$slug] : $map['']; if (!empty($block) && function_exists('getMultiBlock')) { |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I wanted to create a way to switch between MultiBlock sections within a single template so that the content changes depending on the page being viewed. My goal was to avoid building multiple separate templates and adding individual blocks to each one, but instead to have one template where the content can be managed flexibly. As a result, I wrote a simple script that checks which page is currently displayed and loads the appropriate, predefined MultiBlock. This allows me to easily switch blocks within a single template and achieve different content without duplicating files.
<?php $slug = !empty($SIMPLE_PAGE) ? $SIMPLE_PAGE : (!empty($PAGE) ? $PAGE : (!empty($_GET['id']) ? $_GET['id'] : '')); $map = [ '' => 'services-multiblock', 'about' => 'company-features-multiblock', 'offer' => 'offer-multiblock', 'product' => 'opinions-multiblock', ]; $block = isset($map[$slug]) ? $map[$slug] : $map['']; if (!empty($block) && function_exists('getMultiBlock')) getMultiBlock($block); ?>In this example, the function loads a MultiBlock depending on the page we are on.
index -> services-multiblock
about -> company-features-multiblock
offer -> offer-multiblock
product -> opinions-multiblock
It can be freely expanded according to individual needs. Maybe it will be useful to someone. :)
Beta Was this translation helpful? Give feedback.
All reactions