Jump to content
Pip

Adding Image in Page Reference Field

Recommended Posts

Hi, Everyone! 

I'm currently working on a page reference field and set it for multiple pages (AsmSelect) for the input. Is there a way for me to add an image field (aka Avatar) and the title of page in the radio button? 

I used the field name enclosed in the { }. Didn't work. It appeared a text instead. 

Thanks in advance and hope to hear from you soon!

Share this post


Link to post
Share on other sites

Welcome to the forums @Pip!

Technically you might be able to use hooks and custom CSS to modify a core Page Reference inputfield such as AsmSelect to include a thumbnail image but it would be quite advanced/challenging.

Instead I suggest you use a third-party inputfield that supports images - see @Macrura's InputfieldSelectize: https://modules.processwire.com/modules/inputfield-selectize/

  • Like 1

Share this post


Link to post
Share on other sites
9 hours ago, Robin S said:

Technically you might be able to use hooks and custom CSS to modify a core Page Reference inputfield such as AsmSelect to include a thumbnail image but it would be quite advanced/challenging.

... indeed ...

18 hours ago, Pip said:

and the title of page in the radio button? 

For some other page reference inputfields like radio buttons or checkboxes the following hook example could be a first approach. I use it for a field to select a system user. Each label is preceded by a user icon. It should work for checkboxes as well. You need to hook in InputfieldCheckboxes then.
 

$this->addHookBefore('InputfieldRadios::render', function($e) {
    $input = $e->object;
    // quick exit
    if ($input->name != 'clients') return;
    $options = $input->getOptions();
	// $key = page ID
    foreach ($options as $key => &$label)  $label = "<i class='fa fa-user'></i> $label";
    $input->setOptions($options);
});

$this->addHookAfter('InputfieldRadios::render', function($e) {
    // quick exit
    if ($e->object->name != 'clients') return;
    $e->return = wire('sanitizer')->unentities($e->return);
});

 

  • Like 1

Share this post


Link to post
Share on other sites
On 5/10/2020 at 8:18 PM, kixe said:

... indeed ...

For some other page reference inputfields like radio buttons or checkboxes the following hook example could be a first approach. I use it for a field to select a system user. Each label is preceded by a user icon. It should work for checkboxes as well. You need to hook in InputfieldCheckboxes then.
 


$this->addHookBefore('InputfieldRadios::render', function($e) {
    $input = $e->object;
    // quick exit
    if ($input->name != 'clients') return;
    $options = $input->getOptions();
	// $key = page ID
    foreach ($options as $key => &$label)  $label = "<i class='fa fa-user'></i> $label";
    $input->setOptions($options);
});

$this->addHookAfter('InputfieldRadios::render', function($e) {
    // quick exit
    if ($e->object->name != 'clients') return;
    $e->return = wire('sanitizer')->unentities($e->return);
});

 

Sorry for the long delay. 

Super new to Processwire. Totally dorking out on the functionalities. It's ah-mazing!

 

So does this mean I have to edit this inside the core itself?

 

Share this post


Link to post
Share on other sites

I'll definitely check this out!  Thank you! Still learning stuff. 😄 Processwire is so fun!

On 5/10/2020 at 10:00 AM, Robin S said:

Welcome to the forums @Pip!

Technically you might be able to use hooks and custom CSS to modify a core Page Reference inputfield such as AsmSelect to include a thumbnail image but it would be quite advanced/challenging.

Instead I suggest you use a third-party inputfield that supports images - see @Macrura's InputfieldSelectize: https://modules.processwire.com/modules/inputfield-selectize/

I'll definitely check this out!  Thank you! Still learning stuff. 😄 Processwire is so fun!

Share this post


Link to post
Share on other sites
1 hour ago, Pip said:

So does this mean I have to edit this inside the core itself?

You don't want to edit anything in the core - you would loose the modifications with the upgrade to a newer PW version...

Share this post


Link to post
Share on other sites
1 hour ago, ottogal said:

You don't want to edit anything in the core - you would loose the modifications with the upgrade to a newer PW version...

Ok. So  howdo I apply the codes suggested in the previous post then? 

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 sambadave
      Hi there
      Short version of question
      Let's say I have a page in the admin that contains a field... Is it possible to output the content from that field on another page in the admin? Almost like a reference.
      Longer version of question (with example)
      A house builder with multiple (60+) developments. They want to be able to create notices/messages that can be added to one or many developments. Handy for things like regional covid lockdowns or temporary office closures due to bad weather.
      My approach for the admin editing options:
      Add each message to each development
      Pros: You edit the message on the development page in context
      Cons: Very time consuming and repetitive if the same message needs to be applied to 60+ developments
        Control all the messages from one admin page and say which development each message should be applied to
      Pros: Easier to add/remove messages to more than one development at a time. Control all messages from one place.
      Cons: Content is not added on development page, which is where typical admin users may expect to find it I went for option 2 due to flexibility, and created a page within the admin for global development notices. This contains a repeater with:
      Field for message to display Checkbox list of all developments. The user can select which ones to apply each message to It's working really well but the only thing is that if the user goes to a specific development in the admin, the relevant messages aren't displayed in context (as they aren't edited on that page and instead on the global development notices page)... which may cause confusion when a new staff member / content admin tries to edit the text but there is no field when they go to the development admin page where they expect to see it...
      Solution???
      I don't require the message(s) to also be editable on the development page, but I wondered if there was a nice way to show it/them somehow. I feel like I am missing something really simple as I'm sure ProcessWire will have a nice way of achieving this, or maybe there are field settings that allow this kind of thing to happen?
      Any ideas on approaches or similar experiences would be much appreciated, even if it is just a much simpler example with the content from one field being shown on another admin page to get the ball rolling.
      Thanks in advance for any advice :)
    • By Rossie
      Hi Everyone,
      I wish to display a gallery of images from multiple pages on the site.  These images have custom fields created through page reference called 'furniture_list_type'.  Each image now has a radio button which has been selected.
      In  the example code below all images appear from the "gallery20", however the selector  "gallery20.furniture_list_type=3390" does not have any effect.  "3390" is the id of the page reference "chair" selected through the page reference.  I wish only images selected as chair to show.
      Hope someone can help with this.
       
      Thanks,
       
      Calum
       
      $imagePages = $pages->find("template=makers-child, gallery20.furniture_list_type=3390") ;                     foreach($imagePages as $p) {     echo "<ul>";     foreach($p->gallery20 as $image) {         echo "<li><img src='{$image->url}'>{$image->furniture_list_type}</li>";     }     echo "</ul>";      }
    • By daniel_puehringer
      Hi community, thanks for the great work you do 🙂

      I´m looking for a global field which can be used in the footer and has only one instance for all pages. So I´m kind of looking for "One field to rule them all".
       
      Reason for my question: The website I´m currently building has one footer for all pages. The content of the footer should be dynamic - therefore I made a global field which is automatically inserted into each page.
      Problem: if I want to change something in the footer, I have to do it for all fields, because each field has it´s own instance.

      Question: is it possible to have one global field in which changes the content for the footer of all pages?

      In most CMS Systems a simple solution to this is often impossible, I hope that processwire is different 🙂

      All the best,
      Daniel
       
    • By dfile
      Hello, i must count products per category like so:
      category 1 (4 products)
      --category 1.1 (2 products)
      ----category 1.1.1 (1 product)
      and so on.
      category 1 --category 1.1 ----category 1.1.1 ----category 1.1.2 ----category 1.1.3 --category 1.2 ----category 1.2.1 ----category 1.2.2 ----category 1.2.3 produkts have page references for the categories:
      product 1 -- page reference->category 1.1.1 -- page reference->category 1.1.3 -- page reference->category 1.2.2 -- page reference->category 1.2.3 what is the best way to do this, i have many categories and many many products.
      Thank you.
       
    • By Robin S
      Page Reference Default Value
      Most ProcessWire core inputfield types that can be used with a Page Reference field support a "Default value" setting. This module extends support for default values to the following core inputfield types:
      Page List Select Page List Select Multiple Page Autocomplete (single and multiple) Seeing as these inputfield types only support the selection of pages a Page List Select / Page List Select Multiple is used for defining the default value instead of the Text / Textarea field used by the core for other inputfield types. This makes defining a default value a bit more user-friendly.
      Note that as per the core "Default value" setting, the Page Reference field must be set to "required" in order for the default value to be used.
      Screenshot

       
      https://github.com/Toutouwai/PageReferenceDefaultValue
      https://modules.processwire.com/modules/page-reference-default-value/
×
×
  • Create New...