Jump to content

Page Table data on a multilingual website (frontend)?


Christophe
 Share

Recommended Posts

Hello,

I'm using a Page Table field for the first time.
With ProcessWire 3.0.54 and the new "regular" profile (first time with both also).

The default language is French (title: fr) and the second language is English (name: en, title: en).
English pages have /en/ added after the domain name, French pages nothing...

I've eventually managed to have this added piece of code (almost) working in tarifs.php (at first a copy of basic-page.php):

<div class="uk-overflow-auto" pw-append='content-body'>
  <table class="uk-table uk-table-hover uk-table-striped uk-table-small uk-table-middle">	
    <?php
    echo "<caption>";
    $label = 'label';
    if ($user->language->name != 'default') {
    $label = "label{$user->language}";
    }
    // Output label in correct language
    echo $page->fields->grilleTarifaire->$label;
    echo "</caption>";
    echo "<thead><tr>
            <th>{$fields->lot->$label}</th>
            <th>{$fields->superficie->$label}</th>
            <th>{$fields->faces->$label}</th>
            <th>{$fields->tarif->$label}</th>
            <th>{$fields->prixAuMetreCarre->$label}</th>
            <th>{$fields->etat->$label}</th>
            </tr></thead>";    
    ?>       
    <tbody>
    <?php foreach($page->children("template=grille-tarifaire, include=hidden") as $l): ?>		
	  <tr>
      <td><?=$l->lot?></td>
      <td><?=$l->superficie?></td>
      <td><?=$l->faces?></td>
      <td><?=$l->tarif?></td>
      <td><?=$l->prixAuMetreCarre?></td>
      <td><?=$l->etat?></td>
    </tr>		
		<?php endforeach; ?>
    </tbody>
  </table>
</div>

What is working (now) when changing the language to English:

  • the caption changes to the English translation of the Page Table field's label,
  • the English translations appear in the header cells (th) of the table (if there is a translation, otherwise nothing appears...)

What is not working when changing to English:

  • in French, all the data entered in the backend via the Page Table field is displayed in <td>s, but in English nothing is generated between <tbody> and </tbody>.
    The fields' types: 1 TextLanguage, 4 integers (2 are required, 1 has the option "Number (HTML5)"), and 1 float. 

I'm stuck now. So any help is welcome... Thanks in advance!

NB: I have Tracy Debugger installed in case...
Edit: the website is developed online for this project.

Link to comment
Share on other sites

I'm trying to find out if something in the backend is preventing it.

For the Page Table field, in grilleTarifaire -> Access, View is not checked by default for guest (everyone), but checking it doesn't seem to change anything.
I'm not sure what difference it makes.

Also, I've just changed the superuser's language to English for testing purposes, and now in the page Tarifs, for the Page Table field, I see the label and data translated when it is text. 
Is it "normal", for this type of field, that there aren't tabs to switch languages in the Tarifs page? It's not really necessary but I am wondering if there's a (small) relation between this fact and the one that the English page version doesn't display the data on the frontend.

I'm seeing that for the superuser role I don't have lang-edit checked. Checking it doesn't seem to change anything, so I'm unchecking it.

As I'm using a Page Table field, ProcessWire 3.0.54, and @ryan's new "regular" profile for the first time (so, for the first time also, all together with multilingual functionality, otherwise I've already created multilingual websites), there could be many reasons why it's not working. 

There's probably a way to make it work in the frontend but I'm not good enough for the moment to find the solution right now.

Link to comment
Share on other sites

Your code looks good.

Please check if the checkbox for english under settings tab is checked. This could be a reason.


The pages of your pagetable are stored as children of the page where the pagefield lives in. You have the option to change this in the fieldsettings. To keep this option without changing your code you should loop like so

<?php foreach($page->grilleTarifaire as $l): ?>

instead of

<?php foreach($page->children("template=grille-tarifaire, include=hidden") as $l): ?>

 

Link to comment
Share on other sites

Thank you @kixe for your help.

Which settings tab are you referring to please?
Edit: if it's the one in the Tarifs page, it is already checked.

I have already tried with

<?php foreach($page->grilleTarifaire as $l): ?>

and have just retried but when doing so there is no data for the French version/page also on the frontend.

I probably have to find a way to check for the language like I "succeeded" in doing so (but after some hours and variations testing).
But here it is different, I almost know nothing about the different methods to retrieve data from a Page Table (with also multilingual data), and there seems to be even less information about it than for repeaters in the forums (even less with the multilingual aspect).

I had to put include=hidden in order for the data to be displayed in French as the children pages are hidden...
And I've put template=grille-tarifaire in case other (children) pages, not used for the Table Page field, are added later.

Edit 2: for the labels I "just" had to use $label = "label{$user->language}"; and some other pieces of code, as a possible solution.
But for the fields' language-specific values I don't currently know how to "call" them.

Link to comment
Share on other sites

I am talking about the pages with template 'grille-tarifaire' (values of your page table). Check under settings tab: access, status and if second language is enabled (checked).
Why did you set the page status to hidden? If you want to show the values you need to publish the page.
The page is anyway not accesible directly if you don't have a template file 'grille-tarifaire' for the output.

  • Like 1
Link to comment
Share on other sites

Thank you so much @kixe!

The solution was "right in front of me" but I wasn't seeing it.

I imported the data from a csv file (before a LibreOffice Writer table that I copied/pasted in a Calc Spreadsheet) with the help of Import Pages from CSV files (first time using it also).
And later used Batch Child Editor (perhaps first time also) to hide them all at once and do another operation.
But the children pages are only hidden, not unpublished. If not hidden, by default with the site profile used, I have them all displayed as links, so I just hide them.
And hidding them also rapidly makes them less "emphasized" in the backend.

I've just had to activate the English language now manually for the 27 pages, one by one...

I wonder if I still need the language-checking pieces of code already in place, but as it works I won't try it now and remove them for this project.

  • Like 1
Link to comment
Share on other sites

1 hour ago, Christophe said:

I've just had to activate the English language now manually for the 27 pages, one by one...

What about the "Active" column in BCE's edit mode - you should be able to activate the current language (selected in your profile) for all pages at once with this.

Another option is the "Page Active Languages Batcher" in the AdminActions module, which lets you enable or disable active status of multiple languages on multiple pages at once.

  • Like 1
Link to comment
Share on other sites

Thanks again Adrian for your modules.

1 hour ago, adrian said:

What about the "Active" column in BCE's edit mode - you should be able to activate the current language (selected in your profile) for all pages at once with this.

Indeed. I was expecting to see this option in BCE's edit mode, but as the superuser's language was French (default) at that moment it wasn't displayed (which seems normal) and I didn't think of checking it with English.

1 hour ago, adrian said:

Another option is the "Page Active Languages Batcher" in the AdminActions module, which lets you enable or disable active status of multiple languages on multiple pages at once.

As for Admin Actions, I didn't think of going there after to see if there was an action that could do the job, even though (I think) I felt (a bit) it could be the case.
Perhaps it seemed too good to be true, or after not finding it (logically) via BCE I just thought of doing it manually as quickly as possible.

  • Like 1
Link to comment
Share on other sites

2 minutes ago, Christophe said:

as the superuser's language was French (default) at that moment it wasn't displayed (which seems normal) and I didn't think of checking it with English.

A little OT, but the Language Switcher in AdminOnSterdoids is awesome for working with the the multi-language capabilities of BCE because it let you switch languages from a dropdown on the top menu.

58c6e12543d80_ScreenShot2017-03-13at11_12_23AM.png.679fdde24a3f547fccf192126dcfc4d2.png

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