Jump to content

Get Text Tags array from the text field to create checkbox filter


Ksenia
 Share

Recommended Posts

Hello all! I am pretty new to PW and now trying to figure out how to build a filter that uses AND logic and includes many fields. With help I have figured out Page Reference fields and Repeaters, but simple Text Filed with dropdown text tags makes me confused.

As I think of it, first I need to get the array of given fixed options of Text Tags here:

567479215_Screenshot2021-10-28at18_56_47.thumb.png.dca096ce795c1b42e718bf1567d554e0.png

And then I just need to print it out as checkbox form and circle through each page to see if they have the checked value in place of this field. 

Like what I have with page references:

1879794457_Screenshot2021-10-28at19_00_24.thumb.png.ce5de79794f47d32fbc1a1ad19eb46ae.png

But for the life of me I cannot figure out how to get this list...So if you have suggestions, I would really appreciate it!

Best,

Kseniia

  • Like 1
Link to comment
Share on other sites

This might be what you're looking for: 

https://processwire.com/api/ref/inputfield-text-tags/tags-array/ 

Corrected, this is the link:

https://processwire.com/api/ref/inputfield-text-tags/get-tags-list/

You can also get the inputfield from the field like this:

https://processwire.com/api/ref/field/get-inputfield/

Something like this might work, haven't tested: 

$inputfield = $page->getInputfield('tags_field');
$list = $inputfield->getTagsList(true);
foreach($list as $item){
   // echo checkboxes ?
}

 

Link to comment
Share on other sites

On 10/28/2021 at 7:31 PM, elabx said:

This might be what you're looking for: 

https://processwire.com/api/ref/inputfield-text-tags/tags-array/ 

Corrected, this is the link:

https://processwire.com/api/ref/inputfield-text-tags/get-tags-list/

You can also get the inputfield from the field like this:

https://processwire.com/api/ref/field/get-inputfield/

Something like this might work, haven't tested: 

$inputfield = $page->getInputfield('tags_field');
$list = $inputfield->getTagsList(true);
foreach($list as $item){
   // echo checkboxes ?
}

 

Thank you a lot! I adjusted it to my code and it works well!

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.
  • Similar Content

    • By Ksenia
      Hello! 
      I am a new user of PW and I really need some guidence. :---)
      I use PW to design a front-end for the researchers I intern with. They logged all their database with PW (but before only used admin backend).
      I use Page Reference field mostly to create filters. I have followed this tutorial (very grateful for it!) and it does work as you can see at the screen recording of the test-website.

       
      But I cannot figure out how to change the inner workings of it to combine the tags user presses like Russia&&esoterism to see only the items that have both of those tags. 
      What is even more complex: I will have multiple filters working in the same manner (page reference field) and I need all of them to also be using && logic. 

      With possibility of clearing the history and showing all documents again. 
      My tree structure is sth like this:
      -Documents 
                 -document
                 -document
                 -document
      -Tags 
                 -tag
                 -tag
                 -tag
      -Types
                 -type
                 -type
                 -type
      etc
      This is my code right now.
      <div class="row"> <ul class="nav"> <h3> Filter by tag</h3> <li class="nav-item"> <a class="nav-link" href="/Documents/">Show all</a> </li> <?php $docTags = $pages->get("/Tags/")->children; foreach ($docTags as $docTag): ?> <li class="nav-item"> <a class="nav-link" href='<?php echo "/documents/{$docTag->name}/"; ?>' ?> <?php echo $docTag->title; ?> </a> </li> <?php endforeach; ?> </ul> </div> <div class="row py-5"> <?php // only 1 URL segment should be allowed if ($input->urlSegment2) { throw new Wire404Exception(); } // create a string that will be our selector $selector = "template=Document"; // get URL segment 1 $segment1 = $input->urlSegment1; // if there is a URL segment 1 if ($segment1) { // get cat type page $catType = $pages->findOne("parent=/Tags/, name=$segment1"); // if cat type page exists if ($catType->id) { // add this to the selector $selector .= ", tags=$segment1"; } else { // invalid URL segment 1 throw new Wire404Exception(); } } // find the pages based on our selector $docPages = $pages->find($selector); foreach ( $docPages as $docPage): ?> <div class="col-md-4 pb-3"> <div class="card"> <?php // if the page object has a featured image if ( $docPage->featuredImage): // https://processwire.com/api/fieldtypes/images/ // set some default image options $options = array('quality' => 80, 'cropping' => 'center'); // create a new image on the fly 800px wide $img = $docPage->featuredImage->width(400, $options); // get the url to the image $imgUrl = $img->url; // get the description field $imgDesc = $img->description; ?> <a href="<?php echo $docPage->url; ?>"> <img src="<?php echo $imgUrl; ?>" alt="<?php echo $imgDesc; ?>" class="img-fluid card-img-top" /> </a> <?php endif; ?> <div class="card-body"> <h4 class="card-title"> <a href="<?php echo $docPage->url; ?>"><?php echo $docPage->title; ?></a> </h4> </div> </div> </div> <?php endforeach; ?> </div> I would really appreciate any links to resources/tutorials or even general explanation about which direction to take! 
      Thanks in advance! This forum has already helped me a lot!
      Best,
      Ksenia
    • By celfred
      Hello,
      I can't understand how this destructive filter() work.
      Here's my code (with annotations to explain my issue) :
      $teamPlayers = $pages->find("parent.name=players, team=$team"); bd($monster->name.':'.$teamPlayers->count()); // There should be 24 players in my team (which is the case on first call) foreach ($teamPlayers as $p) { $result = $p->child("name=tmp")->tmpMonstersActivity->get("monster=$monster, bestTime>0"); if ($result) { $p->bestTime = $result->bestTime; } else { $p->bestTime = 0; } } $teamPlayers->filter("bestTime>0")->sort("bestTime"); // I want to return only the list of players having a best time on this monster return $teamPlayers;  
      My problem is that after several calls (for all monsters) the number of players in the team is not 24 but 1… I guess the $teamPlayers never resets and I can't understand why line 1 doesn't start with 24 again…
      If I code this for the 2 last lines, it works :
      $teamMates = $teamPlayers->find("bestTime>0")->sort("bestTime"); return $teamMates; But I would like to understand what's going on with my 1st version (I guess it is the destructive aspect of filter()) 😞
      So if someone could take a little time to explain, I would appreciate 🙂
    • By Saleena Jhon
      Hello There, I have saw a post that was covering event-calendar with php, ajax and js. That was showing a monthly overview when I click on a "month" button or when I switch the month. And show the events on one particular date when I pick a day. Also, most events are kind of exhibitions and so they have a start date and an end date much later, and occur on each day in-between as well. So on the template I put two date picking fileds date_start and date_end. Is there an elegant way to select the events using the API? If yes, kindly help me out.
      Thanks in Advance
      Regards: 
       
    • 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 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
       
×
×
  • Create New...