Jump to content

Field type select


Frank Vèssia
 Share

Recommended Posts

I need to create profile pages o a website. A profile contains a field named country. When i create a new profile i want to have a select with all the countries i can choose. I saw i can have this linking pages and choosing a page with a select but i cannot create a page for every country. Is there a better solution?

Thanks

Link to comment
Share on other sites

I don't think there is currently better solution

Why can you create page for every country? with API, you can automatize it, i.e. create template, which parses some CSV and adds children to a hidden page, call it once and you're all done.

Is there any problem with this?

Link to comment
Share on other sites

Actually, hidden pages are ideal. Just put them into root next to 404 and other hidden pages. Have one root with url '/countries/' and in your template, you'll even have quite self-explaining code like

  echo '<select>';
  foreach ($pages->get('/countries/')->children() as $country)
    echo "<option value='{$country->name}'>{$country->title}</option>";
  echo '</select>';

note: this is considering you left original 'title' field as name for that country

this all is good, when you don't wish to have any content for countries. If you do, reconsider placement of 'countries' parent to be better placed in your site structure

More information about data import automation: How do I import lots of data into pages?

Link to comment
Share on other sites

I agree with what Adam has recommended here. In my sites, I usually create a /config/ page that is hidden, and then place all my selectable pages under there, like /config/countries/, /config/states/, etc. Note that you don't want your actual 'country' pages to be hidden, just the main '/config/' (or /countries/ if you are using that). The advantage of keeping these as pages is that it's easy to add/edit them, and it's easy to setup a template that could list everything in a particular country, for example. Viewing /countries/france/ can produce a list of all pages that have it selected... a huge benefit. If your sites have highly relational structures like this (with indexable URLs) your search engine performance will benefit greatly, and it's just really useful to have for may reasons, taking almost no work on your part.

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...