We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40910
    • 15 Posts
    You're awesome! Problem was in brackets.

    How can now make output another TV in snippet and add numbering?

    <?php
    $docId = $modx->getOption('docId', $scriptProperties, '');
      
    $tv_param = array(
        'contentid' => $docId, 
        'tmplvarid' => 11 // art_lit id (this is fine)
    );
    
    $str = 'TemplateVarResource not found';
    
    {
    $i=1;
    $tvr = '<citation key="key-[[+tv.art_doi]]-'.$i.'">';
    $i++;
    }
    
    $tvx = $modx->getObject('modTemplateVarResource', $tv_param);
    if ($tvx) { // prevents PHP erors if templateVarResource not found
        $artlit = $tvx->get('value');
        $str = str_replace(array('<li>', '</li>'), array($tvr.'<unstructured_citation>', '</unstructured_citation></citation>'), $artlit);
    } else {
        $tv = $modx->getObject('modTemplateVar', 11);
        if ($tv) {
            $str = $tv->get('default_text');
        } else  {
            $str = 'No TV 11';
        }
    }
    
    return $str;
      • 3749
      • 24,544 Posts
      I'm not sure what you mean. Do you want the display of the other TV value to be part of the same output? Is there just one more TV, or are there a bunch of them?
        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
        • 40910
        • 15 Posts
        Yes, I need to get another TV in this snippet (art_doi). And add the numbering for each output line, like: <citation key="key-[[+tv.art_doi]]-1">, <citation key="key-[[+tv.art_doi]]-2">...
          • 3749
          • 24,544 Posts
          Try this:

          <?php
          $docId = $modx->getOption('docId', $scriptProperties, '');
          $tmplvarids = array(
               1 => 11,
               2 => 12, //change to ID of second TV
          );
          
          $str = '';
          $i = 1;
          
          foreach($tmplvarids as $tmplvarid) { 
          
              $prefix = "\n" . '<citation key="key-[[+tv.art_doi]]-'. $i . '"><unstructured_citation>';
              $suffix = '</unstructured_citation></citation>';
              $i++;
              $artlit = '';
          
              $tvx = $modx->getObject('modTemplateVarResource', array('contentid' => $docId, 'tmplvarid' => $tmplvarid ));
          
              if ($tvx) { // prevents PHP erors if templateVarResource not found
                  $artlit = $tvx->get('value');
              } else {
                  $tv = $modx->getObject('modTemplateVar', $tmplvarid);
                  if ($tv) {
                      $artlit = $tv->get('default_text');
                  }
              }
              
              if (empty($artlit)) {
                  $artlit = 'Could not get TV value for TV ' . $tmplvarid;
              }
          
              // $str .= str_replace(array('<li>', '</li>'), array($prefix . '<unstructured_citation>', '</unstructured_citation></citation>'), $artlit);
              // I'm not sure where the li tags are coming from so this seems more straightforward:
          
              $str .= $prefix . $artlit . $suffix;
          }
           
          return $str;
            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
            • 40910
            • 15 Posts
            Almost there, now it like:

            <citation key="key--1"><unstructured_citation><ul>
            <li>Ayad M. F. Influence of tooth preparation taper and cement type on recementation strength of complete metal crowns / M. F. Ayad, W. M. Johnston, S. F. Rosenstiel // J Prosthet Dent. – 2009. – Vol. 102(6). – P. 354−361.</li>
            <li>Begliuk D. A. Functional characterization of the dental pulp and periodontal tissues in patients with partial edentulous / D. A. Begliuk // Res and Educ J. «Health and education in the XXI century». – 2010. – Vol. 12(8). – P. 377–379.</li>
            <li>Conrad H. J. Current ceramic materials and systems with clinical recommendations: a systematic review / H. J. Conrad, W. J. Seong, I. J. Pesun // J Prosthet Dent. – 2007. – Vol. 98(5). – P. 389–404.</li>
            <li>Davidovich G. The use of CAD/CAM in dentistry / G. Davidovich, P. G. Kotick. // Dent Clin North Am. – 2011. – Vol. 55(3). – P. 559–570.</li>
            <li>Etman M. K. Quantitative measurement of tooth and ceramic wear: in vivo study / M. K. Etman, M. Woolford, S. Dunne // Int J Prosthodont. – 2008. – Vol. 21(3). – P. 245−52.</li>
            <li>Gasiuk P. A. The influence of orthodontics preparation for the unfixed orthodontic constructions on the tooth pulp from the point of view of morphology / P. A. Gasiuk, V. B. Radchuk, P. P. Brekhlichuk [еt al.] // Intermedical J. – 2015. – Vol. 3(5). – P. 39–43.</li>
            <li>Hazhva S. I. Analysis of errors and complications of prosthetics using unremovable prosthetic constructions / S. I. Hazhva, G. A. Pashinian, A. A. Alyoshin // J Dent. – 2010. – Vol. 2. – P. 7–8.</li>
            <li>Li R. W. Ceramic dental biomaterials and CAD/CAM technology: State of the art / R. W. Li, T. W. Chow, J. P. Matinlinna // J Prosthodont Res. – 2014. – Vol. 58(4). – P. 208−216.</li>
            <li>Mously H. A. Marginal and internal adaptation of ceramic crown restorations fabricated with CAD/CAM technology and the heat-press technique / H. A. Mously, M. Finkelman, R. Zandparsa [еt al.] // J Prosthet Dent. – 2014. – Vol. 112(2). – P. 249−256.</li>
            <li>Radchuk V. B. Influence of odontopreparation under the metal-ceramic construction on the tooth tissue / V. B. Radchuk, P. A. Hasiuk, S. O. Rosolovska // Clin Dent. – 2015. – Vol. 3-4(12-13). – P. 129–130.</li>
            <li>Reitemeier B. A prospective 10-year study of metal ceramic single crowns and fixed dental prosthesis retainers in private practice set tings / B. Reitemeier, K. Hänsel, C. Kastner [еt al.] // J Prosthet Dent. – 2013. – Vol. 109(3). – P. 149−155.</li>
            <li>Іvanitsky І. O. Comparative characteristics of morphometric parameters and histostructure dental hard tissues under conditions of ultrasonic and classical odontoprepations / І. O. Іvanitsky, N. V. Gasyuk, І. Yu. Popovich // Bulletin of the Ukrainian Academy of Medical Dental: Actual problems of modern medicine. – 2013. – Vol. 13(2). – P. 202–205.</li>
            </ul></unstructured_citation></citation>
            <citation key="key--2"><unstructured_citation>10.26724/2079-8334-2017-3-61-9-11</unstructured_citation></citation>


            Then it should be:
            <citation key="key-10.26724/2079-8334-2017-3-61-9-11-1"><unstructured_citation>Ayad M. F. Influence of tooth preparation taper and cement type on recementation strength of complete metal crowns / M. F. Ayad, W. M. Johnston, S. F. Rosenstiel // J Prosthet Dent. – 2009. – Vol. 102(6). – P. 354−361.</unstructured_citation></citation>
            <citation key="key-10.26724/2079-8334-2017-3-61-9-11-2"><unstructured_citation>Begliuk D. A. Functional characterization of the dental pulp and periodontal tissues in patients with partial edentulous / D. A. Begliuk // Res and Educ J. «Health and education in the XXI century». – 2010. – Vol. 12(8). – P. 377–379.</unstructured_citation></citation>
            ... etc.
              • 3749
              • 24,544 Posts
              As far as I can tell, this problem is not in the code I provided. It is in whatever sets the following placeholder:

              [[+tv.art_doi]]
                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
                • 40910
                • 15 Posts
                Li tags coming from TV art_lit. This is the textarea with lists like <ul><li>...</li><li>...</li>...</ul>.

                This code outputs something, that I need:

                $docId = $modx->getOption('docId', $scriptProperties, '');
                $tmplvarids = array(
                     1 => 11,
                     2 => 17, 
                );
                
                $str = '';
                $i = 1;
                 
                foreach($tmplvarids as $tmplvarid) { 
                
                    $prefix = "\n" . '<citation key="key-[[+tv.art_doi]]-'. $i . '">';
                    $suffix = '';
                    $i++;
                    $artlit = '';
                 
                    $tvx = $modx->getObject('modTemplateVarResource', array('contentid' => $docId, 'tmplvarid' => $tmplvarid ));
                 
                    if ($tvx) { // prevents PHP erors if templateVarResource not found
                        $artlit = $tvx->get('value');
                    } else {
                        $tv = $modx->getObject('modTemplateVar', $tmplvarid);
                        if ($tv) {
                            $artlit = $tv->get('default_text');
                        }
                    }
                     
                    if (empty($artlit)) {
                        $artlit = 'Could not get TV value for TV ' . $tmplvarid;
                    }
                
                    $str .= str_replace(array('<li>', '</li>'), array($prefix . '<unstructured_citation>', '</unstructured_citation></citation>'), $artlit);
                
                }
                
                return $str;


                Output:

                <ul>
                
                <citation key="key--1"><unstructured_citation>Ayad M. F. Influence of tooth preparation taper and cement type on recementation strength of complete metal crowns / M. F. Ayad, W. M. Johnston, S. F. Rosenstiel // J Prosthet Dent. – 2009. – Vol. 102(6). – P. 354−361.</unstructured_citation></citation>
                
                <citation key="key--1"><unstructured_citation>Begliuk D. A. Functional characterization of the dental pulp and periodontal tissues in patients with partial edentulous / D. A. Begliuk // Res and Educ J. «Health and education in the XXI century». – 2010. – Vol. 12(8). – P. 377–379.</unstructured_citation></citation>
                
                <citation key="key--1"><unstructured_citation>Conrad H. J. Current ceramic materials and systems with clinical recommendations: a systematic review / H. J. Conrad, W. J. Seong, I. J. Pesun // J Prosthet Dent. – 2007. – Vol. 98(5). – P. 389–404.</unstructured_citation></citation>
                
                <citation key="key--1"><unstructured_citation>Davidovich G. The use of CAD/CAM in dentistry / G. Davidovich, P. G. Kotick. // Dent Clin North Am. – 2011. – Vol. 55(3). – P. 559–570.</unstructured_citation></citation>
                
                <citation key="key--1"><unstructured_citation>Etman M. K. Quantitative measurement of tooth and ceramic wear: in vivo study / M. K. Etman, M. Woolford, S. Dunne // Int J Prosthodont. – 2008. – Vol. 21(3). – P. 245−52.</unstructured_citation></citation>
                
                <citation key="key--1"><unstructured_citation>Gasiuk P. A. The influence of orthodontics preparation for the unfixed orthodontic constructions on the tooth pulp from the point of view of morphology / P. A. Gasiuk, V. B. Radchuk, P. P. Brekhlichuk [еt al.] // Intermedical J. – 2015. – Vol. 3(5). – P. 39–43.</unstructured_citation></citation>
                
                <citation key="key--1"><unstructured_citation>Hazhva S. I. Analysis of errors and complications of prosthetics using unremovable prosthetic constructions / S. I. Hazhva, G. A. Pashinian, A. A. Alyoshin // J Dent. – 2010. – Vol. 2. – P. 7–8.</unstructured_citation></citation>
                
                <citation key="key--1"><unstructured_citation>Li R. W. Ceramic dental biomaterials and CAD/CAM technology: State of the art / R. W. Li, T. W. Chow, J. P. Matinlinna // J Prosthodont Res. – 2014. – Vol. 58(4). – P. 208−216.</unstructured_citation></citation>
                
                <citation key="key--1"><unstructured_citation>Mously H. A. Marginal and internal adaptation of ceramic crown restorations fabricated with CAD/CAM technology and the heat-press technique / H. A. Mously, M. Finkelman, R. Zandparsa [еt al.] // J Prosthet Dent. – 2014. – Vol. 112(2). – P. 249−256.</unstructured_citation></citation>
                
                <citation key="key--1"><unstructured_citation>Radchuk V. B. Influence of odontopreparation under the metal-ceramic construction on the tooth tissue / V. B. Radchuk, P. A. Hasiuk, S. O. Rosolovska // Clin Dent. – 2015. – Vol. 3-4(12-13). – P. 129–130.</unstructured_citation></citation>
                
                <citation key="key--1"><unstructured_citation>Reitemeier B. A prospective 10-year study of metal ceramic single crowns and fixed dental prosthesis retainers in private practice set tings / B. Reitemeier, K. Hänsel, C. Kastner [еt al.] // J Prosthet Dent. – 2013. – Vol. 109(3). – P. 149−155.</unstructured_citation></citation>
                
                <citation key="key--1"><unstructured_citation>Іvanitsky І. O. Comparative characteristics of morphometric parameters and histostructure dental hard tissues under conditions of ultrasonic and classical odontoprepations / І. O. Іvanitsky, N. V. Gasyuk, І. Yu. Popovich // Bulletin of the Ukrainian Academy of Medical Dental: Actual problems of modern medicine. – 2013. – Vol. 13(2). – P. 202–205.</unstructured_citation></citation>
                </ul>10.26724/2079-8334-2017-3-61-9-11


                But it outputs TV art_doi only once at the end of the file (10.26724/2079-8334-2017-3-61-9-11).
                [ed. note: extrim25 last edited this post 8 years, 11 months ago.]
                  • 3749
                  • 24,544 Posts
                  If that's the whole output, it looks like you're only processing 1 TV. The key should change because $i is incremented each time through the loop.

                  The $prefix, which contains the art_doi tag should appear anywhere the selected TV has an li tag. I can't explain why that would only happen once at the end unless there is only one li tag in the TV and it's at the end. [ed. note: BobRay last edited this post 8 years, 11 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
                    • 3749
                    • 24,544 Posts
                    From the full output, I'd say that everything is working as expected, but only one TV is being processed successfully. Are you sure that:

                    1. The ID of the both TVs is correct in the code
                    2. Both TVs are connected to the template used by the page
                    3. Both TVs are not hidden by either a Resource Access ACL entry or an Element Category ACL entry
                    4. Both TVs are not empty

                      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
                      • 40910
                      • 15 Posts

                      1. Correсt
                      2. Connected
                      3. Where to check this? Not see any option for this
                      4. Not empty (art_doi output at the end of file, but its not from [[art_doi]] TV)