[[+content_image]]
E
E
eugene1592020-07-02 21:37:57
MODX
eugene159, 2020-07-02 21:37:57

Why does pdoPage reset the context when switching to another news page? How to fix it?

There is a news page. It has pdoPage. Here is the challenge:

[[!pdoPage?
    &elementClass=`modSnippet`
    &element=`pdoResources`

    &parents=`2`
    &tpl=`allnewsItem`
    &includeTVs=`newsImg, newsDate`
    &prepareTVs=`1`
    &depth=`0`
    &limit=`6`
    &includeContent=`1`

    &ajax=`1`
    &ajaxMode=`default`

    &pageVarKey=`page`
    &pageNavVar=`page.nav`
]]

There are two contexts on the site - web (by default, it is Russian) and en (English).
The news card has a snippet call, the result of which depends on the context. Here is an example code.
<?php
switch($context = $modx->context->key) {
  case 'web':
    $result = 'Привет';
    break;
  case 'en':
    $result = 'Hello';
    break;
}

return $result;

If I go to the English version of the site, open the page with the news, the card will display "Hello". Then I will go, for example, to page 2. And the card will display "Hi". Although I'm still on the English version of the site.

Why is this happening? It should print "Hello".
How can this be fixed?

Using lexicons is not an option, because string in a real project is created dynamically.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
Anton Tarasov, 2020-07-03
@an-tar

pdoPage supports the &context parameter common to all snippets from the pdoTools package, pass the context there from the system parameter like this:

[[!pdoPage?
    &elementClass=`modSnippet`
    &element=`pdoResources`

    &parents=`2`
    &tpl=`allnewsItem`
    &includeTVs=`newsImg, newsDate`
    &prepareTVs=`1`
    &depth=`0`
    &limit=`6`
    &includeContent=`1`
    &context=`web`
    &ajax=`1`
    &ajaxMode=`default`

    &pageVarKey=`page`
    &pageNavVar=`page.nav`
]]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question