Jump to content

select - how to?


bwakad
 Share

Recommended Posts

After reading some topics and watching the video page field, I am not following the concept of making a select at all...

In Admin I did the following:

I created a template called "Selects";

I created a page called "Branche" and 2 children called "yes" and "no";

I created a page fields type called "select_branche" and used the "Branche" page as parent;

In the admin under pages > settings, it has an option called template, and it has "Selects" as default. Do I need to make this my normal template from site profile??? which can be "basic-page" or "home"...?

Then it also says in the wiki: Add this new field to your template in the usual way.

But what template are we talking about???

And what is the usual way? echo $select_branche; ???

ps. I am using PW2.4 with foundation 4 site profile

Link to comment
Share on other sites

There is already a thread going for this, but here you go:

1. Create TWO templates.

Create a template called select-parent and a template called select-option - For this example neither need a template file, though they would need one if you wanted to display these actual pages.

Edit select-parent and under family click on Allowed Template for Children and choose select-option. You don't have to do this part, but it does make for neater management.

2. Add to the template select-option two fields

Title - well it will have that one anyway

Value - this can be any field type. 

Note: If your title and value are going to be the same, then don't bother with a second field.

3. Go to pages and create your parent page.

For this example we will just make this a child of the home page, but it can be anywhere within your tree structure.

Click on home and create a new child page.

Choose select-parent as the template and call it My Select and save. 

Optionally, under settings, check the Hidden box to hide this page from the front end. (It will be anyway as it has no template file)

Save and close this page.

4. Click on your new My Select page and Create a child page.

Make whatever children you need. If you restricted the allowed templates for children, it will automatically use the select-option template, if not, you will need to choose that template.

5. Go to fields and create a new field of the type Page.

Create the field, naming it as you need and save. 

Under the Details tab choose: Single page (Page) or empty page (NullPage) when none selected

Under the input tab change the parent of selectable pages to My Select.

Scroll down and change input field type to select.

Save

And that is it. You can now include this page field in whatever template you need. You can add options as you require, but I would be careful about deleting them!

  • Like 4
Link to comment
Share on other sites

Thanks, this explanation was very very clear. You are really patient!

I finally added the field to my template from within the admin, and used in the template FILE on the server

echo $page->select_branche;
But in front-end it is being outputted as numbers.
Do you know where I have to go to fix this?
Link to comment
Share on other sites

If you want to echo the title, just do $page->select_branche->title

Without specifying a field on that page you only get the page ID. You can also get the name and any other fields in a similar way.

  • Like 1
Link to comment
Share on other sites

My mistake. In the cheatsheet I noticed

$field->name

So I went along and tried this:

echo $page-select_branche->name;

and that works!

Many many thanks for everyone who wanted to stay patient...

Link to comment
Share on other sites

But as you saw in your other topic, title was what you were after as I said :)

On the cheatsheet, you want to be looking at the variables under $page for the built-in fields like title etc. : http://cheatsheet.processwire.com/

When you edit a page in the admin on a default installation, the fields are usually labelled with the field name. If you go to Setup -> Templates in the admin and edit the basic-page template for example, it will list the fields you can use in your template file - $page->summary, $page->body etc.

When you reference a page that is somehow linked to the current page as in your example (a Page field that's a select list) then you have access to all the fields in that page's template. For example, if your select_branche page template had a field called "something" then you could output its value like this: echo $page->select_branche->something

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