Jump to content

[SOLVED] Create multilingual pages with $pages->new via API and set the Title


chuckymendoza
 Share

Recommended Posts

I may have a simple problem, but I can't find a solution, yet.
 
I have a multilanguage Website and like to create a new page via the API with $pages->new
The names of my languages are "default" and "english" ("en" in my environment)
 
What I want: set the title of each page the same, in the default and on the English page. 
I already have set the name identical for both languages with: 
$happynewyear->set('name', $jahreszahl, 'default'); // set the name for the default language
$happynewyear->set('name', $jahreszahl, 'en'); // set the name for the en language
And this code works.

Problem: this seems not to work with the title of the pages. (Page Title (Multi-Language) is activated
When I visit the default site, the title is set correct, but not for the english page.
And when I visit the english page first, the title is set correct for the english page, but not for the default page.
 
Am I missing something?
 
Thanks for your help in advance!
-Thomas
 
 
$happynewyear = $pages->new([
'template' => 'programm_jahre',
'parent' => '/programm/archiv/',
'name' => $jahreszahl
]);
$happynewyear->set('name', $jahreszahl, 'default'); // set the name for the default language
$happynewyear->set('name', $jahreszahl, 'en'); // set the name for the en language	
$happynewyear->set('title', $jahreszahl, 'default'); // set the title for the default language
$happynewyear->set('title', $jahreszahl, 'en'); // set the title for the en language			
$lang="english"; // $lang is the language you want to set as active, e.g. 'english' for French
$langObj = $languages->get("name=$lang"); // Get the language object for the second language	
$happynewyear->set("status$langObj", 1); // Set the status of the page's second language to active
$happynewyear->save("status$langObj"); // Save the page with the second language status set to active

 

 

 

Link to comment
Share on other sites

Yes, THANKS A LOT! This gave me the crucial hint!

This is the code that worked for me:

$happynewyear = $pages->new("template=program_jahre, parent=/programm/archiv/, name=$jahreszahl");
$happynewyear->setOutputFormatting(false); // disable output formatting
$happynewyear->of(false); // disable the output formatting API
$langObjDE = $languages->get("name=default"); // Get the language object for the default language
$langObjEN = $languages->get("name=english"); // Get the language object for the second language	
$happynewyear->setLanguageValue($langObjDE,'name',$jahreszahl);  // set name of page for default language
$happynewyear->setLanguageValue($langObjDE,'title',$jahreszahl); // set title of page for default language
$happynewyear->setLanguageValue($langObjEN,'name',$jahreszahl);  // set name of page for second language
$happynewyear->setLanguageValue($langObjEN,'title',$jahreszahl); // set title of page for second language
$happynewyear->setLanguageValue($langObjEN,'status',1); // set status of page for second language to active
$happynewyear->save(); // save

 

  • Like 1
Link to comment
Share on other sites

  • chuckymendoza changed the title to [SOLVED] Create multilingual pages with $pages->new via API and set the Title

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...