Jump to content

Get active children


speculatius
 Share

Recommended Posts

Hello,

I have been playing with PW for last 2 months. So far everything was really intuitive and straightforward. However, I get into some strange behaviour yesterday and I would like to let you know about it.

I build website with 2 languages - default and english. All pages exist for default language, but only some of them are active for english. Let's say this is the structure:

Home

+ About (default + english language)

+ Contact (default language only)

Now I execute the following code:

$user->language = $languages->get('default');
$children = $homepage->children;

As you would expect, variable $children contains pages [about, contact]. Also if I execute...

$user->language = $languages->get('english');
$children = $homepage->children;

...variable $children contains pages [about]. But here comes the trick. Let's execute this:

$user->language = $languages->get('default');
$defaultChildren = $homepage->children;

$user->language = $languages->get('english');
$englishChildren = $homepage->children;

You would expect, that $defaultChildren == [about, contact] and $englishChildren == [about]. But that is NOT true. Both of them contain [about, contact].

The problem probably is, that first call to $homepage->children is cached somehow. If you call it second time, language change is ignored and the same output is given again.

Workaround for me is to make second call little different, but semanticaly the same. For example:

$user->language = $languages->get('default');
$defaultChildren = $homepage->children;

$user->language = $languages->get('english');
$englishChildren = $homepage->children('parent=' . $homepage);

And that is all :) Have a nice day.

Martin

  • Like 1
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...