Jump to content

[API] show field label


buothz
 Share

Recommended Posts

Hi, i've this field:

NAME LABEL TYPE NOTES TEMPLATES

bandiera Flag TextLanguage

1

I also did a search on the forum and the API section but could not find answer, is I use

echo $page->bandiera;

I will only output the value (italia for example), I would rather have as output

LABEL: VALUE (Flag: Italia for example)

thank u...

  • Like 1
Link to comment
Share on other sites

Welcome to the forums Buothz! Good question. Here's how you could do it:

$language = $languages->get("spanish");
$field = $fields->get('bandiera');
$label = $field->get("label$language");  
echo "$label: $page->bandiera";

If you want a specific other language replace the first line above with this:

$language = $languages->get('italia');

.

Edit: Code fixed first example and changed to make more sense. (Soma)

  • Like 1
Link to comment
Share on other sites

Welcome to the forums Buothz! Good question. Here's how you could do it:

$field = $fields->get('bandiera');
$label = $field->get("label$language");  
echo "$label: $page->bandiera";

If you want a specific other language replace the line above with this:

$italia = $languages->get('italia');
$label = $field->get("label$italia");

thank u ;) another little question, to show "FieldsetOpen" and "FieldsetOpenTab" with API?

Edited by buothz
Link to comment
Share on other sites

another little question, to show "FieldsetOpen" and "FieldsetOpenTab" with API?

These two fieldtypes don't have any function outside of the PW PageEdit Process, so aren't really applicable in the API for the most part. Let me know if I've misunderstood your question? If you are building a form elsewhere, it's more likely that you would want to use the InputfieldFieldset:

$form = wire('modules')->get('InputfieldForm');
$form->attr('method', 'post'); 
$form->attr('action', './'); 

$fieldset = wire('modules')->get('InputfieldFieldset'); 
$fieldset->label = 'This is a fieldset';
$fieldset->description = 'Some optional extra copy if you want it.';

$field = wire('modules')->get('InputfieldText');
$field->attr('name', 'title'); 
$field->label = 'Title';

$field->description = 'Extra description';

$fieldset->add($field);
$form->add($fieldset);
echo $form->render();
Link to comment
Share on other sites

These two fieldtypes don't have any function outside of the PW PageEdit Process, so aren't really applicable in the API for the most part. Let me know if I've misunderstood your question? If you are building a form elsewhere, it's more likely that you would want to use the InputfieldFieldset:

$form = wire('modules')->get('InputfieldForm');
$form->attr('method', 'post');
$form->attr('action', './');

$fieldset = wire('modules')->get('InputfieldFieldset');
$fieldset->label = 'This is a fieldset';
$fieldset->description = 'Some optional extra copy if you want it.';

$field = wire('modules')->get('InputfieldText');
$field->attr('name', 'title');
$field->label = 'Title';

$field->description = 'Extra description';

$fieldset->add($field);
$form->add($fieldset);
echo $form->render();

Thank you so much for your prompt reply, I just want to take the field and divide them into categories, so I decided to use the fieldset to preserve the multi-language.

For example: http://www.yachtbrok.../barca37016.htm

"specifiche" in English must be specific.

But if I use an editable field risk being edited by the user should not edit it instead ...

To have an ordered structure wanted to use the possibility of fieldset ...

Otherwise I can use simple PHP like IF or SWITCH

if ($_GET['language']=='it') {
echo 'specifiche';
 } else {
 echo 'specifics';
 }

thanks again

Edited by buothz
Link to comment
Share on other sites

You may also want to look at using multi-language fields, or multi-language alternate fields for this (if you aren't already):

http://processwire.com/api/multi-language-support/multi-language-fields/

As for detecting a language from a URL, a GET var is a fine way to go. Though note that you'll want to keep your templates cache settings off, since GET vars aren't cachable. Other options include a URL segment (if turned on in your template) or a subdomain.

A URL segment might look like this (for english): /boats/barca37016/en

if($input->urlSegment1) {
   $language = $languages->get($sanitizer->pageName($input->urlSegment1)); 
   if($language) $user->language = $language; 
}

A subdomain might look like this (for english): en.yachbrokers.com

$name = strstr($config->httpHost, '.', true); // requires PHP 5.3
$language = $languages->get($sanitizer->pageName($name));
if($language) $user->language = $language;
  • Like 1
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...