We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40088
    • 708 Posts
    Revo 2.5.2
    getUrlParam
    TagLister
    NewsPub
    TinymceWrapper

    I'm using NewsPub and TinymceWrapper (specifically TinyMagicPublisher) for front-end editing and TagLister for filtering. Everything works fine.

    The NP forms use several TVs, all of which have a single-word name except for two TVs which use 2 words with a space between. One is a text field [ [*field text] ] and the other a picker [ [*field picker] ].

    "field text" is optional and works as expected. Meaning if given a value the form is saved, the resource is created and the TV value appears on the front-end. All good.

    However, "field picker" is required
    &required=`field picker...`
    but its value is not being saved, and the resource is not created. The exception is if it is not an optional field in which case everything works perfectly.

    I also tried a different naming convention: "fieldPicker", and of course it worked perfectly so clearly something about a name with two separate words is causing a problem, but only if the field is required.

    But I need the field to be required and I need to use "field picker" (2 words) when displaying tagLister results.
    [[!getUrlParam? &name=`key`]]
    The two-word naming scheme makes more sense when displaying front-end results.

    Is there any way around this using regex or some other PHP sleight-of-hand, or am I stuck with a single word TV name?

    This question has been answered by BobRay. See the first response.

    [ed. note: todd.b last edited this post 7 years, 4 months ago.]
      Todd
      • 3749
      • 24,544 Posts
      The exception is if it is not an optional field in which case everything works perfectly.

      Erm ... "not an optional field" == "required". I assume you mean that it's fine when the field is not required. wink

      That said, I can't see any reason why having a space should cause a problem as long as the &required property has back-ticks around the full value and the name is spelled exactly the same in the &required property as it is in the &show property, and in the name attribute of the form.

      TVs have both a name and a caption field so you can use a name with no space but still display the TV's caption (with a space) when displaying the TV in the front end.

      It's a policy for some of us to have the 'name' field space-free just to avoid the problem you're having. The problem should never happen, but when you're using a bunch of code from other developers it could.
        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
        • 40088
        • 708 Posts
        [Laughs] Yes, that's what I meant.

        Ok, so it shouldn't be a problem. That's good to know. Normally I would avoid the space when naming elements but in this case it would be useful.

        Out of curiosity, in the
        [[!getUrlParam? &name=`key`]]
        call is there a way to display the TV "Caption" in the filter results instead of the TV "Name"?

        Reason being, I could stick with a single-word TV name which means I avoid any problems creating new resources, but I could still display a multi-word phrase (i.e. 'Caption') when using `getUrlParam` which, when all is said and done, is the desired end-result. [ed. note: todd.b last edited this post 7 years, 4 months ago.]
          Todd
          • 3749
          • 24,544 Posts
          If you're using NewsPublisher, you can use the &captions property to show a custom caption for any field.

          For displaying the caption, it would depend on what you're using to aggregate them. For example, I'm not sure if getResources sets all TV fields or just the value field when processing the Tpl chunk.

          You could just try this in your inner Tpl chunk and see if it works:

          [[+caption]]


          Worst case, you could write a simple snippet to get the captions using the TV ID as a property.

            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
            • 40088
            • 708 Posts
            Well, here's the specific code used to filter tag results:
            <dd title="Filter by ‘Time’">
            	Completion Time: [[!toLinks?
            	    &items=`[[*time]]`
            	    &target=`22`
            	    &tpl=`Specs Link`
            	    &tagKey=`time`
            	]]
            </dd>

            Then on the results page I'm using [[!getUrlParam? &name=`key`]] to display the TV name time in [[+resultsMessage]].

            But instead of showing the TV name time I want to show the caption completion time in [[+resultsMessage]].

            I've been experimenting with
            [[+caption]]
            but so far I've been unable to get the desired result.
              Todd
              • 3749
              • 24,544 Posts
              You're putting that caption tag in the Specs Link Tpl chunk, right?

              If it doesn't work, I think you could make it work by hacking the toLinks code, but I'm not sure.

              This might work as an alternative (in that same Tpl chunk). Put this where you want the caption to appear:


              [[ShowCaption? &name=`[[+name]]` ]]


              Then create this snippet.


              <?php
              /* ShowCaption snippet */
              $output = '';
              
              $name = $modx->getOption('name', $scriptProperties, '', true);
              
              if (!empty($name)) {
                 $tv = $modx->getObject('modTemplateVar', array('name' => $name));
              
                 if ($tv) {
                     $output = $tv->get('caption');
                 }
              }
              
              return $output;
              



              As a last resort, you could do it with lexicon strings, like this (mn. is just a prefix to avoid collisions):

              [[%mn.[[+name]]? &namespace=`mynamespace` &topic=`default` &language=`en`]] 


              This uses the name as a lexicon key for the caption.

              To do it this way, you'd have to:

              1. Create the mynamespace namespace.
              2. Go to Lexicons on the System Menu (gear icon) in the Manager.
              3. Select the mynamespace namespace, the default topic, and the language.
              3. Click on the Create Entry button.
              4. Put mn.name (where name is the name of the TV) in the name field.
              5. Put the caption in the value field.
              6. Save
              7. Repeat for each name => caption pair.

              Try it with one or two first to make sure it's working.
                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
                • 40088
                • 708 Posts
                Well, the first two suggestions didn't work for me. By the way, here's the default 'Specs Link' Chunk (tpl) mentioned above,
                <a href="[[+url]]">[[+item]]</a>

                It looks like I will need to try your Lexicon suggestion. Hopefully I'll have better luck.

                Thank you.
                  Todd
                  • 3749
                  • 24,544 Posts
                  If you put a [[+name]] placeholder in the 'Specs Link' Chunk (tpl), does it show the TV name?

                  If so, you might try this with the ShowCaption snippet above:

                  [[!ShowCaption? &name=`[[+name]]` ]]


                  The exclamation point will delay the processing of the snippet until (hopefully) the name placeholder is populated.

                  This really should work unless I've made a mistake in the code.
                    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
                    • 40088
                    • 708 Posts
                    When placed in the 'Specs Link' Chunk the [[+name]] placeholder does not show the TV name.
                      Todd
                    • discuss.answer
                      • 3749
                      • 24,544 Posts
                      Ouch. I finally took a look at the toLinks code. It doesn't set any extra placeholders. That means none of the methods above will work.


                      I think this might:

                      [[!ShowCaption? &name=`[[!getUrlParam? &name=`key`]]`]]


                      Same snippet as before except for line 3:

                      <?php
                      /* ShowCaption snippet */
                      $output = 'No Caption';
                       
                      $name = $modx->getOption('name', $scriptProperties, '', true);
                       
                      if (!empty($name)) {
                         $tv = $modx->getObject('modTemplateVar', array('name' => $name));
                       
                         if ($tv) {
                             $output = $tv->get('caption');
                         }
                      }
                       
                      return $output;


                      ********************

                      If that doesn't work, I think this will (and will be faster anyway):

                      [[!ShowCaption]]


                      <?php
                      /* ShowCaption snippet */
                      $output = 'No Caption';
                      
                      $fields = array('name' => 'key');
                       
                      $name = $modx->runSnippet('getUrlParam', $fields);
                       
                      if (!empty($name)) {
                         $tv = $modx->getObject('modTemplateVar', array('name' => $name));
                       
                         if ($tv) {
                             $output = $tv->get('caption');
                         }
                      }
                       
                      return $output;


                      [ed. note: BobRay last edited this post 7 years, 4 months ago.]
                        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