Jump to content

Getting tab label in different languages on frontend fails


Recommended Posts

Posted

Hello @all,

I have tried to output the overridden label from a specific tab inside my template on the frontend.

I have used this documentation: https://processwire.com/api/ref/template/get-tab-label/

The tab name is called "tab1" and the labels were overriden with "Kontakt" (German) and "Contact" (English).

To output the label depending on the language on the frontend I use the following code snippet:

$tablabel = $page->template->getTabLabel('tab1');
echo $tablabel;

and 

$tablabel = $page->template->getTabLabel('tab1', $user->language->id);
echo $tablabel;

But both versions output only the default (German) tab label. I appreciate your help. Is there something that I am missing?

But both version output an empty string, so it seems that the overridden values will not be taken into account.

Posted

i think theres a missing comma :-)

$tablabel = $page->template->getTabLabel('tab1', $user->language->id);

 

  • Thanks 1
Posted
4 minutes ago, zoeck said:

i think theres a missing comma

Sorry this was only a writing mistake. In the original code the comma is present.

Posted
34 minutes ago, Juergen said:

Sorry this was only a writing mistake. In the original code the comma is present.

Oh, okay :) 

When i use "$user->language->id" inside of the "getTabLabel", theres an error (tracy ;))...
You can use it without "->id":

$tablabel = $page->template->getTabLabel('tab1', $user->language);

i checked it, and it works :) 

  • Like 1
Posted (edited)

Okay, same problem here with the FieldsetTabOpen Field...

I just checked it with the default "content" tab of the template...

 

/edit:

okay, now i get the Label ;) 

$tablabel = $page->fields->tab1->getLabel($user->language->id);

 

Edited by zoeck
Posted

Ok, I ended up with the following codes

in site/_init.php

//get labels, title, values and descriptions in different languages
if ($user->language->name != 'default') {
    $title       = "title{$user->language}";
    $value       = "value{$user->language}";
    $label       = "label{$user->language}";
    $description = "description{$user->language}";
    $notes       = "notes{$user->language}";
} else {
    $title       = 'title';
    $value       = 'value';
    $label       = 'label';
    $description = 'description';
    $notes       = 'notes';
}

 

and on the page itself:

echo $page->template->fields->getFieldContext('tab1')->$label;

Pay attention to "$label" instead of "label".

The same can be achived by using description, notes,....

  • Like 1

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...