K
K
Kevin Mitnick2019-05-01 20:00:45
MODX
Kevin Mitnick, 2019-05-01 20:00:45

Why are there problems with the output of snippets in MODX Revolution through chunks?

There is MODX Revolution 2.7.1. This is not the first time (and on previous versions of modx) there are problems with the output of snippets. I can't understand why the snippet "breaks" and how to fix it.
Here is the code:


And here is what is displayed on the frontend:
5cc9d0346938d905320121.png
In this case, the snippet pulled up all the input parameters and processed them correctly, but often the processing of input parameters is interrupted at some particular one. Specifically, in this project, this is the 4th time such a problem has arisen, and I absolutely do not understand why. Who faced this and how can it be cured? In the database, everything seems to be in the correct form and I don’t observe any constructions that would contribute to such behavior of the snippet.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kevin Mitnick, 2019-05-02
@volfing

For the time being, I've been "shackled", I hope that the reason and the solution will be found.
Created snippet "snippetRunner":

<?php
if(empty($snippet)){
    return;
}

if(!empty($params)){
    $params = str_replace("`", "", $params);
    $params = json_decode($params, true);
    
    foreach($params as $key => $value){
        if(strpos($key, "htmldecode_") !== false){
            $params[str_replace("htmldecode_", "", $key)] = htmlspecialchars_decode($value);
        }
    }
}

$content = $modx->runSnippet($snippet, !empty($params) ? $params : []);

return !empty($content) ? $content : (!empty($params["if_empty"]) ? $params["if_empty"] : "");

I wrote in the template:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question