A
A
Albert2022-02-04 14:03:33
PHP
Albert, 2022-02-04 14:03:33

How to display data in MODX depending on the received value from the snippet?

Hello. There is a project on MODX. There is a Services page, data is displayed according to the template, but there is one page (as an exception) in which the page structure is different. There are blocks that are not in the template. And I need to add a separate html block purely for it and display certain values ​​there.

I decided to use the snippet to determine which page it is, depending on the last value in the URl, if this is the page I need, then I need to display this block. In pure php, this is easy to do, but in MODX it is done differently, I can’t figure it out in any way. Can you suggest?

getURL snippet to define page in URL
$url = $_SERVER['REQUEST_URI'];
$path = parse_url($url, PHP_URL_PATH);
$pathParts = explode('/', $path);
$result = array_pop($pathParts);

This is how I access the getUrl snippet I need, I need to check if the value of $result = beauty, then we display the desired block.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Vasiliev, 2022-02-04
@timurusubyan

If the structure is different, it's a different template and output whatever you want there.
If the structure is not very different, but there are features, then check by the current id.

on fenom is slightly simpler
{ if $_modx->resource.id == '' }
...
{ /if }

D
Danny Arty, 2022-02-04
@DanArst

Too difficult. Isn't it easier to just check for id and display the necessary content based on this, because each page has a unique identifier.
If you have fenom enabled, which is what I advise you, then the code will look like this (instead of 15 put your page id) :

{if $_modx->resource.id == 15}
<section class="section">
          <div class="container-fluid">
              BEAUTY Блок 
          </div>
</section>
{/if}

If fenom is not enabled and for some reason you do not want to enable it, then you can write the condition like this:

A
alexalexes, 2022-02-04
@alexalexes

Bare chunk syntax:


Using the If snippet (you need to install the package of the same name):

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question