Jump to content

Getting a select field from a template and outputting in module


louisstephens
 Share

Recommended Posts

I have been following @bernhard's great tutorial on creating a Dashboard and everything has very easy to understand so far. However, I need to add a select field that a template is using (so users can create a new page from the dashboard), but I am really at a complete lost on how to achieve this. I have been googling, but can't really find anything on the matter.

	$field = $this->modules->get('InputfieldSelect');
      $field->name = "Select Manufacturer";
      $field->findPagesSelector = "template=basic-page"; //not needed for select field
      $field->labelFieldName = "title";
      $field->name = "Manufacturer Select";
      $field->columnWidth = 34;
      $fieldset->add($field);

I have the above code, which was originally an InputfieldPage, but since this is an options field, I have changed it. Has anyone actually gotten a select from a template (and its' values) in a module?

Link to comment
Share on other sites

Not sure I understand exactly what you're asking, but InputfieldSelect (and other related inputfields such as AsmSelect) has the addOption() method.

So if you wanted your selectable options to be derived from all the pages using the basic-page template you could do this:

$basic_pages = $this->pages->find("template=basic-page");
foreach($basic_pages as $basic_page) {
    // Page ID is value, page title is label
    $field->addOption($basic_page->id, $basic_page->title);
}

 

  • Like 1
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

×
×
  • Create New...