Jump to content
fruid

return "select" field options of ProFields Table

Recommended Posts

Inside the ProFields Table I have one column of type "select" for which I entered several options to choose from. 

How can I return these options? I mean loop through them to build my markup.

Share this post


Link to post
Share on other sites

The API for this is kinda ugly but it works.

Where "3" is the number (in order) of the subfield / column you are looking for.

image.png.6e1ff7cbc71f5e4d10d836cf49456f87.png

  • Like 1

Share this post


Link to post
Share on other sites

thanks!

I figured out my own approach, works as well…

$cols = $page->table->getColumns();
foreach($cols[10]['options'] as $opts => $value) {
	$out .= '<option value="'.$value.'">'.$value.'</option>';
}

 

  • Like 1

Share this post


Link to post
Share on other sites
4 minutes ago, fruid said:

I figured out my own approach, works as well…

I think that is actually the approach I've used in the past as well!

  • 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 Guy Incognito
      I've created a simple sports league fixture generator in a template called 'League'. Teams are added as page references then a fixture list is created as a ProFields table by hooking page save to add new rows to the table.
      The bit I need help with is that I'm trying to check a fixture doesn't already exist before adding it to the table (e.g. if a new team is added to the league). I'm trying to do this with a PW selector to filter the fixtures table and check whether Team A vs Team B already exists in the table. Then on the next line checking no fixture was found by using count().
      However as soon as I add the selector the script no longer adds any rows to the table. If I take it out, it all works fine (albeit with duplicate fixtures each time the page is saved). I've also tested the selector in a page template and it filters as expected. It's late here (UK)... I'm probably doing something stupid! Any ideas?
      <?php //Hook page save to generate league fixture lists $wire->addHookAfter("Pages::saved(template=league)", function ($event) { //Get which page has been saved $page = $event->arguments(0); $noFixturesAdded = 0; //For each team in league cycle through and add home fixtures foreach ($page->teams_in_league as $teamA) { foreach ($page->teams_in_league as $teamB) { //Check if fixture already exists $existingFixtures = $page->fixtures("team_a=$teamA,team_b=$teamB"); //Check team A is not the same as team B as you can't play yourself //Then add row to fixture table if ($teamB != $teamA && $existingFixtures->count() < 1 ) { $fixture = $page->fixtures->makeBlankItem(); $fixture->team_a = $teamA->id; $fixture->team_b = $teamB->id; $page->fixtures->add($fixture); $noFixturesAdded ++; } } } //Save updates to table $page->save('fixtures'); $message = "League saved. $noFixturesAdded new fixtures were added"; $this->message($message); });  
    • By Reid Bramblett
      OK, after three days of banging my head against this, I turn to the forums.
      I am attempting to apply what would seem to be a rather straightforward filter to a set of results, but am tripping over... something (suspect it's because I continue to have difficulty wrapping my brain around the operation of the ProFields Table field; also, a bit shaky on PageArrays in general).
      I have a links page that includes a "title" field, a "categories" field and a "urls" ProFields Table.
      The urls Table has rows/fields for "poiurl" (the actual full url), "urltext" (the link as I want it to appear), "desc" (an optional description field), and "place" (a dropdown select populated by another page).
      I can get the appropriate links page (filtered by a previously defined "$pcat" category), grab all the urls from the Table, and display them. However, I cannot figure out how to limit those results by a particular field—in this case, "place," as I want to return only those links that match the current page's "place."
      $place=$page->place; $links = $pages->get("template=links, categories=$pcat"); echo "<h4>$links->title</h4> <ul>"; foreach ($links->urls as $u) { if ($u->desc) echo "<li><a href='$u->poiurl'>$u->urltext</a> ($u->desc)</li>"; else echo "<li><a href='$u->poiurl'>$u->urltext</a></li>"; } echo "</ul>"; So, how do I get it to show only the $u results wherein $u->place=$place? 
      Thanks!
×
×
  • Create New...