Sten

How to access to fields value

Recommended Posts

Hi,

I have a lot of difficulties with getting a field value.
First I created a template, inside I created several fields
two fields are a dropdown select box So I have a value and a label for each line.

Then I want to get the field value in _init.php or in the template to display it. How can I get the value of a field for the page ? I need to understand the flow through which data goes.
Could someone help me ?

Thank you

 

 

 

Share this post


Link to post
Share on other sites

Why don't you use a pagefield?

It's as simple as using $page->fieldname (inside the template).

In _init.php, you would use $pages->get(123)->fieldname, where 123 is the id of the page your field lives in.

If you have multiple instead of single values, you would have to loop through them, but that's easy as well.

Share this post


Link to post
Share on other sites

Thank you Dragan,

I do that then i want to transform data to display in my template :

$view->set('categorie',${"cats_".$lang}[$page->cat]);

Here I have an array for each language. $page->cat displays an integer, I tested it. If I replace $page->cat with an integer to test, it works but with the expression as a key, it does not work.

Share this post


Link to post
Share on other sites

This article has helped me. It's still incomplete (commented at the end) but I think there is enough information to solve the issue.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you Rick, your tip helped me much. I used
 

$page->cat->id;

Now it works 🙂

  • Like 1

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Falk
      Hi!
      I have lots of blogposts in my pagetree and I want the pagelabel to include the value of the post’s datefield (only the year).
      Adding date | title in the template settings results in something like…
      1536012000 | my blogpost title
      Is it possible to convert the timestamp to a readable date?
       
    • By ridgedale
      Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.
      I am trying to add a field that provides a dropdown menu but there are no Options or Selector(s) type available - see attached image of field types available.
      The following reference under the docs does not appear to be applicable any more:
      https://processwire.com/api/modules/select-options-fieldtype/
      I can't see how to achieve this. Any assistance would be appreciated.

    • By mjut
      Hello!
      I am trying to get some extra css-file into my admin templates. I managed to modify my admin.php to this:
      <?php namespace ProcessWire; require($config->paths->adminTemplates . 'controller.php'); echo "<link rel='stylesheet' type='text/css' href='" . $config->urls->templates . "css/admin.css'>"; By doing so, the css <link> is added to the very end of each parsed admin-html. (right AFTER the closing </body> tag.)
      That causes some trouble. e.g. the page tree is not displaying any more. Although, other pages are working - like the edit form of a page.
      My question: is there a correct way of adding my extra css to the admin area?
      Thanks for you help!
      Stephan
       
    • By karian
      I don't know why multiple instances (repeater_repeat_columns1, repeater_repeat_columns2, ...) of my repeater field are displayed inside Template field (see image).
      Is there a way to clean/reset it ?
       

    • By awebcreature
      Hello there
      I need a field with realtime percent calculation (without page save)  with values from other fields in admin template. I think about jQuery with onChange methods on corresponding fields but this is not clear for me how to do this in module. Any help with some advice or example will be highly appreciated! 
      Thanks in advance!