Jump to content

Only show language-field or nothing instead of default language field


Recommended Posts

Hi there,

Surfed the Forum, but couldn't find an answer to my problem :-s


I have two languages and want to show a field ONLY when it has a value in the correct language;

For the default language I can create a simple check offcourse ($page->fieldname = '') 

But how about the alternate language (Let's say Dutch 1017)

To make things more complex, I use this in a sub-function so the main variables of PW aren't arround.

Any ideas?

Michiel

Link to comment
Share on other sites

Hi Michiel,

Easiest solution would be to use the latest dev version of ProcessWire.

There's a setting in each text field which is configured as multilang under the "Details" tab:

Language Support / Blank behaviour
What should happen when this field's value is blank?
[ ] Inherit value from default language
[x] Remain Blank

Choose "Remain Blank" should fix your problem.

  • Like 2
Link to comment
Share on other sites

In a subfunction they aren't available? wire("languages") ? Is available everywhere.

But how about the alternate language (Let's say Dutch 1017)

this should maybe work.

$lang = $languages->get("dutch");
$dutch_field = $page->get("fieldname$lang");

or

$lang = $user->language;
$user->language = $languages->get("dutch");
if($page->fieldname) { ... }
$user->language = $lang;
Link to comment
Share on other sites

  • 2 weeks later...

2.4 will be released once the dev branch source has sat for a week or so without any necessary fixes or major additions (meaning, it's reached a stable state). I think that's probably soon, but don't want to promise any dates since I'm actively working on the code almost every day. 

  • Like 5
Link to comment
Share on other sites

  • 1 month later...

edit:

well, that was easy :-)

$f = $fields->get("title");
$f->set("langBlankInherit", 1);
$f->save(); 

I'll keep it here, in case someone else searches for the same thing...

Is there an API function to change the language support blank behaviour?

e.g. change the behaviour of dozens of multilang fields via API? (from "show default language" to "blank" or vice versa).

I see in the DB-table "fields" an entry like this: "langBlankInherit":1 (field "data"), when set to remain blank...

(Using dev version 2.3.2)

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