We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22213
    • 52 Posts
    I’ve been playing with the NewsListing and I’ve noticed that if I insert the same TV twice in the same news item, each has its id assigned as the same name. This means that I now have 2 css blocks with the same id. I assume this is true of other types of pages.

    This could be a problem when doing DOM operations on the rendered page - is there a workaround for this to ensure unique ids get assigned to TV-based objects? I presume that I could make the output of the TV the input of a snippet that would munge the name(s) appropriately? Or maybe the name of new ids could be inserted into a static variable whose value could be checked at runtime?

    I’m completely new to MODx so I’m trying to be cautious before making changes to the code.

    Anyone out there able to inform me further?
      Web Designer
      PHP Programmer
      Cocoa Developer
      Boulevardier & Arriviste
      • 18397
      • 3,250 Posts
      Do you mean that in the NewsListing tpl if you have an item with a id it gets duplicated for every entry?

      If so, this is the nature of how repeating programs work. They output the same thing multiple times changing only relevant values. The best solution is to use a class for repeating items or to use an id name with a TV in it (such as "myidname[+id+]"
        • 22213
        • 52 Posts
        Quote from: Mark at Mar 31, 2006, 01:11 PM

        Do you mean that in the NewsListing tpl if you have an item with a id it gets duplicated for every entry?

        If so, this is the nature of how repeating programs work. They output the same thing multiple times changing only relevant values. The best solution is to use a class for repeating items or to use an id name with a TV in it (such as "myidname[+id+]"

        Mmm, no. I mean that If I use a simple inserted TV in a template like [*#lulaHead*] as a generic html tag, in this case h3, then MODx provides an id for it, in this case ’tvtvlulaHead’. No class or id was assigned when the TV was created. This seems to be default behaviour by the system, not anything to do with any templated or user-selection. If I provide an id, it puts that in, but that’s a user-directed choice.

        This is not a major issue, but my suggestion was that, since an id needs to be unique to be useful, the parsing code could determine if that id name had been used before, at least in the scope of the inserted object, which in this case is [*content*]. Otherwise, just turn it off since I can’t use a selector to reliably control that block anyway.

        The naming convention could be ’tvtvlulaHead_1’, ’tvtvlulaHead_2’ or whatever.

          Web Designer
          PHP Programmer
          Cocoa Developer
          Boulevardier & Arriviste
          • 18397
          • 3,250 Posts
          Ok, I see what you mean. That should be looked into. But what does this have to do with NewsListing?
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            @Mark: nothing, he just noticed it when using NewsListing and he had the same TV twice in the same news item.

            ...I’ve noticed that if I insert the same TV twice in the same news item, each has its id assigned as the same name.

            If this is a problem, just don’t use the output widget, that’s what automatically inserts an ID in the tag, and put the tags as part of the default value:

            <h3 class="h3">Heading</h3>
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 4385
              • 372 Posts
              Is this going to be addressed? It produces invalid html.
                DropboxUploader -- Upload files to a Dropbox account.
                DIG -- Dynamic Image Generator
                gus -- Google URL Shortener
                makeQR -- Uses google chart api to make QR codes.
                MODxTweeter -- Update your twitter status on publish.
                • 4385
                • 372 Posts
                Here is a quickie solution... maybe this post should be moved, since this is not a ditto issue.

                You need to change your widget output from HTML Generic tag to Delimiter

                <?php
                // [[MakeBullets? &myList=`[*skills*]` &myId=`skill`]]
                
                if (!isset($myId)){$myId="item";}
                if (!isset($myList)){$myList="";}
                $myList = split(',',$myList);
                $output = '';
                for($i=0; $i<count($myList); $i++) {
                	$output .='<li id="' . $myId . '_' . $i .'">' . $myList[$i] . '</li>';
                }
                $output = '<ul id="' . $myId . 's">' . $output . '</ul>';
                return $output;
                ?>


                Maybe there should be a repository for mini-snippets? Would this be wiki worthy?
                  DropboxUploader -- Upload files to a Dropbox account.
                  DIG -- Dynamic Image Generator
                  gus -- Google URL Shortener
                  makeQR -- Uses google chart api to make QR codes.
                  MODxTweeter -- Update your twitter status on publish.