Jump to content

$pages->get finds a multi-language page only in some languages


loukote
 Share

Recommended Posts

Dear forum members,

I'm facing the following issue: on a website with multi-language support, there is a template having a multi-language title, ML body and few more fields. The "parent" template looks for pages (news items) using a selector:

$pages->get("template=news_entry, sort=-created, Publish_in*=main")

The selector does not change with the language.

The page (and it's parent) have the multi-language support enabled. The pages (parent getting the pages using the above selector and the "news entry") have the cache disabled and the languages active.

Now the problem: a test news entry shows up (selector finds a page) in the default language and one other, it does not show up in two others. The one non-default in which it shows up was installed later.

I went through the documentation but I'm blank on what needs to be checked. Would you have any ideas on what needs to be corrected or checked? I would really appreciate!

Link to comment
Share on other sites

On 9/3/2018 at 10:51 PM, tpr said:

Also, get() ignores published state which is perhaps not what you want.

Sorry, the template used find(), not get(). So it's something else.

PW is 3.0.110, upgraded to PW 3.0.111 results in the same behavior.

Standard pages work fine. Only the news-list page where subpage are pulled through the api (first $pages->find(), then foreach() ) behaves this way (counts/returns a number of items for some languages and none for others). This is the case whether the field (title, body) is translated or not.

is there a way in the api to check whether a page language is active?

Link to comment
Share on other sites

Use Tracy debugger and dump to see th3 full object. I guess you should post the template file content too to check that also (with the exact data to avoid misunderstandings like the previous get vs find).

Link to comment
Share on other sites

@tpr , thanks for offering help!

Which full object? bd($page); ? I'm new to Tracy debugger and do not know how to export the result in a manner that would be readable.

The template is as follows:

<?php namespace ProcessWire;

// basic-page.php template file

// Primary content is the page's body copy
$content = $page->body;

// List all news
$section_title  = $pages->get('id='.$section_name_id)->title;
$limit_news_to_subsites_string = ", Publish_in*=".$section_title;

$selector ="template=news_entry, sort=-created" . $limit_news_to_subsites_string;
$items = $pages->find( $selector );

$item_nr = 0;
foreach($items as $item){
	$item_nr++;
	
	$news_entry = renderNews($item, $item_nr, true, false, 'full', $user);
	
	// Output this piece of news 
	$content .= "<div class='news_entry'>".$news_entry."</div>\n";
}

When the language is either French or German, the counter $item_nr==0, for English and Luxembourgish it is ==1 or more, depending on the number of test news items.

I tried to activate and deactivate the languages on news/item pages (items to be displayed) and the news page itself (the one that should list them all). No change.

The only difference i see is on the admin panel: the languages that return news items do have a drag-and-drop icon and text (lb), not those that return zero news items (de). But this likelu has something to do with the language packs: for FR and DE there is one, for LB there is none.

image.thumb.png.a7c3a38b41311953264825d6ccab3e74.png

image.thumb.png.cc9593845f7bbd9dbd49ac4bd64e33a0.png

Link to comment
Share on other sites

Just bd() what you need to see, eg.

bd($section_title);
bd($selector);
bd($items);

and examine what the cause could be.

My guess is that there's something with the $section_title, or some news page are still inactive in some languages (de, fr).

  • Like 1
Link to comment
Share on other sites

When the page is displayed directly via its own template, languages switch as expected, that is correct title and body are displayed. Only when accessing them through

$pages->find( $selector )

the language switching somehow fails. So nothing to see with

bd($page->title);

On the other hand, Tracy (discovering: it's great!) shows the result of

bd($items);

image.thumb.png.9a1e3deb66af9053467517332b699960.png

image.png.421a9e1332b05ab767d5a08c1b016a5a.png

(Somehow i do not see a better way to dump it here.)

The URL is there but i still need to understand how to display the body and title. So far so good, the family is calling...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...