We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39498
    • 169 Posts
    Is there a way to have predefined tags from e.g. a picklist, so that the editor just can pick, but not edit the tags?
      • 42562
      • 1,145 Posts
      Excellent question!
      Looking for something fixed, so editors don't always have to type in something new, or try to remember what tag already exists, only to get the spelling wrong?

      If you insist on using Articles Tags because it is easier than building yours, and you want to enjoy searching documents by tags in the Articles Manager, here are a few tweaks.
      A quasi solution that works... the warranty does not cover any side effects... (I doubt there'll be any though)

      We want to turn the stubborn Articles Tags into a set of predefined selectable Categories....

      Note! The tags use a hidden TV called articlestags, which is assigned to no template, but somehow magically works (via PHP), and can even accept multiple input.

      To use this TV for your own purposes
      1. In the TV INPUT, change Hidden to Single Listbox
      (Auto-tag is cool, it shows you all the Tags you've ever created to choose from - but you can't pre-create Tags/Categories...sucks!)
      (Multi Listbox, will allow for multiple Tags - in OUTPUT set the delimiter to comma sign <==this input option works but is buggy)
      2. Enable Type-ahead: NO
      3. Force Selection to List: NO
      4. Insert your predefined options Science||Religion||Politics||Baked Bread||Baked Beans
      4. Give TV access to your articles' template
      Voila!

      Open your blog article...oops! now the original tag field that comes with Articles is present and so is the same thing in the Template Variable Tab. Huge interference, you can't use your version - because the Tags Field will always save, save nothing, that means it will remove the tags you chose in the Template Variable Tab.

      We need to
      remove the Tag box completely (good luck in finding how) or
      remove the code that makes the original Tag field save, thus rendering it visible but useless

      Articles forces you to meddle with its core code, so you can't help it, although this is bad practice.
      Open yourMODx/core/components/articles/model/articles/article.class.php
      The culprit are lines 623 - 661 <==adjust at your own peril
      //$tvc->save(); If you comment out line 646, you should be fine.

      And you are done, like Indian curry!
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 19328
        • 433 Posts
        Thank you donshakespeare! Your explanation really helped me. I wanted the tags to behave like autotag so I followed your explanation but changed the input type to autotag.

        For removing the now useless tag box from the article edit screen (to not confuse users), open the following files:
        - assets/components/articles/js/article/create.js
        - assets/components/articles/js/article/update.js

        Search for 'modx-resource-tags' . There is one appearance of it in each document. Comment that field out (be careful to leave the right amount of brackets there). Save the file, clear the cache and reopen your article. The 'tag' section which you don't use anymore will be gone. Also don't forget to comment the code in article.class.php out as well like donshakespeare said.

        Of course you are altering the core code here, not good! So make a note and don't forget when updating smiley
        I hope in future updates of Articles we'll be able to choose what kind of tv the 'tag tv' should be. But besides that, Articles is great!
          • 42562
          • 1,145 Posts
          @michelle84
          I am glad you found it helpful.
          Good addition too.
            TinymceWrapper: Complete back/frontend content solution.
            Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
            5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
            • 3749
            • 24,544 Posts
            There's a combination of JS and PHP code in Notify that makes buttons of pre-set tags and inserts them into a comma-separated list in the tag input field when you click on them.

            I think it might work well with Articles tags. It gets the tag list from a chunk, but it could be from anywhere.

            /**
                 * Gets the possible tags from the preList Tpl chunk and, if not empty,
                 * injects the HTML and JS code to let user add tags by clicking on the buttons
                 */
                protected function setTags() {
                    $tags = '';
                    $tagChunkName = $this->modx->getOption('prefListChunkName', $this->props, 'sbsPrefListTpl');
                    $tagList = $this->modx->getChunk($tagChunkName);
                    if (!empty($tagList)) {
            
                        $src = '<script type="text/javascript">
            function nf_insert_tag(tag) {
                var text = document.getElementById("nf_tags").value;
                if (text.indexOf(tag) != -1) {
                   text= text.replace("," + tag + ",","," );
                   text = text.replace(tag + ",","");
                   text = text.replace("," + tag,"");
                   text = text.replace(tag,"");
                } else {
                    if (text) {
                    text = text + "," + tag;
                    } else {
                      text = tag;
                    }
                }
                var tagArray = text.split(",");
                tagArray.sort();
                text = tagArray.join(",");
                document.getElementById("nf_tags").value = text;
            return false;
                }
            </script>';
            
                        $this->modx->regClientStartupScript($src);
                        $tags = '<p>';
                        $tagArray = explode('||', $tagList);
                        natcasesort($tagArray);
                        $i = 0;
                        foreach ($tagArray as $t) {
                            $t = strtolower($t);
                            $pos = strpos($t, '==');
                            $tag = $pos ? substr($t, $pos + 2) : $t;
                            $tag = trim($tag);
                            $tags .= '<button name="button' . $i . '" id="button' . $i .
                                  '" type="button" class="nf_tag" onclick="nf_insert_tag(' .
                                   "'" . $tag . "'" . ');"' . '">' . $tag . "</button>\n";
                            $i++;
                        }
                        $tags .= '</p>';
                    }
                    $this->modx->setPlaceholder('nf_tag_list', $tags);
                }
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 42562
              • 1,145 Posts
              Articles 1.7.5-pl changelog
              New in 1.7.2

              Rebuilt tagging component. Thanks to Jan Peca (TheBoxer)
              @michelle84 and @spica8 This hack seems to no longer work from the back-end.
              But works perfectly when using NewsPublisher to edit Articles' resources. Whatever was done in the rebuilding has both cured and crossed the customization. Will look into it sometime...

              @BobRay I'll have to try your method.
                TinymceWrapper: Complete back/frontend content solution.
                Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.