buothz Posted April 16, 2012 Share Posted April 16, 2012 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... 1 Link to comment Share on other sites More sharing options...
ryan Posted April 16, 2012 Share Posted April 16, 2012 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) 1 Link to comment Share on other sites More sharing options...
buothz Posted April 16, 2012 Author Share Posted April 16, 2012 (edited) 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 April 16, 2012 by buothz Link to comment Share on other sites More sharing options...
ryan Posted April 17, 2012 Share Posted April 17, 2012 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 More sharing options...
buothz Posted April 17, 2012 Author Share Posted April 17, 2012 (edited) 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 April 17, 2012 by buothz Link to comment Share on other sites More sharing options...
ryan Posted April 18, 2012 Share Posted April 18, 2012 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; 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now