Jump to content
Sign in to follow this  
steveooo

How to set same title to every language/page

Recommended Posts

Hello,

when using the default multi-language module, you can set different titles for each language on a page.

The logic is: the default language is the source and every non-default language inherits from it if empty.

For a use case I have, I need to update all title's on a page for every language via the API.

I tried a little with this code but it doesn't work (with no errors):

$globalTitle = 'Test';
foreach ($languages as $language) {
    $page->set('title'.$language->id, $globalTitle);
}

Share this post


Link to post
Share on other sites

$globalTitle = 'Test';

foreach ($languages as $language) {

        $page->of(false);

        $page->setLanguageValue($language, 'title', $globalTitle);

        $page->save('title');

}

Share this post


Link to post
Share on other sites

I am using following code in my module and it still does not work...

    protected function syncLangProperty($page, $property) {
        if ($this->modules->isInstalled('LanguageSupport') &&
            !empty($page->{$property})) {
            $defaultValue = $page->{$property};

            foreach ($this->languages as $language) {
                $page->of(false);
                $page->setLanguageValue($language, $property, $defaultValue);
                $page->save($property);
            }
        }

        return $page;
    }

Share this post


Link to post
Share on other sites

I cannot test it but in module scope you maybe cannot use the $languages api. Try with wire('languages'). Do you have debug mode on?

Try this one

    protected function syncLangProperty(Page $page, $property) {
        $languages = $this->wire('languages');
        if ($this->wire('modules')->isInstalled('LanguageSupport') &&
            !empty($page->getLanguageValue($languages->getDefault(), $property))) {
            $defaultValue = $page->getLanguageValue($languages->getDefault(),$property);
            foreach ($languages as $language) {
                $page->of(false);
                $page->setLanguageValue($language, $property, $defaultValue);
                $page->save($property);
            }
        }
        return $page;
    }
Edited by kixe

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By NehaPillai
      Hello Everyone, I was trying to update SEO meta title, description and meta keywords for my website in Process Wire CMS but it saving in the backend but it is not reflecting on my website, Please help me regarding this error. Please find below attached screen shot for your ref. TIA.


    • By happywire
      [solution]
      =========================================================
      Using devilbox to develop locally.
      Installing the Beginner, Intermediate and Blank sites from the setup menu works perfect.
      The sites load, all pages load, can access the admin panel, all fine.

      However when installing the Multi-language site, the one I can pick during the setup procedure, things do not work.
      The English Home page works.
      The English About page,
      https://wiremultilang.loc/en/about/ tells me
      Same for the English Sitemap,
      https://wiremultilang.loc/en/site-map/ .
      I have allowed all cookies and can see them when checking in the browser cookies and site data, using Firefox 65.0.1 64-bit on Ubuntu 18.04.2 LTS.
      Clicking "German" on the Home page,
      https://wiremultilang.loc/de/ , shows me the German version of the 404 page.
      Clicking "Finish" on the Home page,
      https://wiremultilang.loc/fi/ , shows me the Finish version of the 404 page.
      What could be the issue here?
      Thank you for your guidance or any help you could supply.
    • By AndZyk
      Hello,
      when you add a page you can see the page name of the page under the page title field. But when you change the page title afterwards, you have to go to the settings tab to also change the page name.
      We have many clients that change the page title afterwards but forget to change the page name, because they don't look in the settings tab or forget it.
      Is it possible to show the page name on the content tab under the page title?
      I hate to say this, but I like how WordPress handles this better:

      Or should I open an GitHub request?
      Regards, Andreas
    • By usualCommission
      Hey everyone,
      I'm pretty experienced with pagination and haven't seen this before. I have my pages pulled using $pages->find, which is working fine however using renderPager() generates pagination where the links do not work. Here are some details.
      All templates needing pagination have pagination enabled in the admin. URL Segments are not enabled. Clicking on the "Next" or numbered links merely reloads the current page. The link href values are properly being output with the urls being /page2, /page3, /page4, etc. Manually entering the paginated urls has the same effect of reloading the current page with no new content. Pages are being returned from the ->find function properly and with the proper limit. A few other details:
      ProcessWire v3.0.98 Multi-language is enabled, 2 languages implemented. Pagination does not work on either language Have very few modules installed (few enough to list), none of which I could see interfering: ProFields, ProDrafts, ListerPro, DB Backups, Cronjob DB Backup, Upgrades, Upgrade Checker, Force Password Change, Markup Sitemap XML I'm stumped. For the sake of being overly-thorough, here's the code:
      <?php $articleTemplates = [ 'template_news_article', 'template_news_video', 'template_news_press_release' ]; $searchParams = [ 'template=' . implode('|', $articleTemplates), 'sort=-published', 'limit=' . $pages->get('template=template_news')->list_count ]; $articles = $pages->find(implode(',', $searchParams)); echo $articles->renderPager(); ?>  
    • By j00st
      Hi all! 
      I've been searching/browsing a bit, but can't find what I'm looking for just yet...
      Perhaps I'm searching in the wrong places, but I thought posting it here might work better/more efficient.
      I need to do the following;
      1. I have the TITLE field (the one set by ProcessWire as default).
      2. There's already a whole lot of pages of the template 'project' set up.
      3. Now I actually want to be able to add <i> and <br> tags to this title...which is possible if I turn off the specialchar encoder...
      ...but it also presents the opportunity for people to start typing, and generate the following kind of URLs:

      TITLE: This is a really long title <br> which <i>needs</i> to be split in two
      URL generated: this-is-a-really-long-title-br-which-i-needs-i-to-be-split-in-tow
      Don't want that happening. So, I thought it might be wiser to do the following.
      Next to the 'title' field, also set a 'display-title' field.
      But, preferably I'd want to generate this for all the projects already in existance...including copying their content to this new display-title field.
      Just adding the field means all the titles will need to be copied...not something I look forward to telling the editors of the site 🙂
      I saw the Hook for on-save, but that's only for the single page...and I'm not an experienced MySQL-coder/user, otherwise I guess that would've been the way to go.
      So I'm really curious to hear if you guys think there are other/better options (and what they are)
      Thanks!
×
×
  • Create New...