We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40910
    • 15 Posts
    Good day. There is a journal site. Installed MODX 2.2.7, Articles 1.6.0. For each issue of the journal, a container is created in Articles, to which articles are added. I need to output TV and other parameters for all articles of the journal release in the prepared XML template, some of which must be preprocessed. To get the articles I use getResources.

    Template:
    [[getResources?
      &parents=`6701`
      &tpl=`TplArticles`
      &showHidden=`1`
      &limit=`8`
      &includeContent=`1`
      &includeTVs=`1`
      &processTVs=`1`
      &sortby=`publishedon`
      &sortdir=`ASC`
      &showLog=`1`]]


    TplArticles:
    <journal_article publication_type="full_text">
       <titles>
         <title>
    [[+pagetitle]]
         </title>
       </titles>
       <contributors>
        <person_name sequence="first" contributor_role="author">
         <given_name>Ann P.</given_name>
         <surname>Shirakawa</surname>
        </person_name>
        <organization sequence="additional" contributor_role="author">Sample Organization</organization> / an organization that has authored the article
       </contributors>
       <publication_date media_type="print">
        <year>[[+publishedon:strtotime:date=`%Y`]]</year>
       </publication_date>
       <pages>
        <first_page>[[+tv.art_pages:limit=`3`]]</first_page>
       </pages>
       <publisher_item>
        <identifier id_type="pii">[[+tv.art_doi:stripString=`10.28824/`]]</identifier>
       </publisher_item>
       <doi_data>
        <doi>[[+tv.art_doi]]</doi> 
        <resource>http://site.com/[[~[[+id]]]]</resource>
       </doi_data>
        <citation_list>
    	[[doiCititationList]]
        </citation_list>
      </journal_article>


    Problem in snippet doiCititationList. I need to output the processed content of TV art_lit for each individual article in the container:

    <citation key="key-10.9876/S0003695199034166-1"> // key must be generated by pattern key-art_doi-number in list
    <unstructured_citation>String 1</unstructured_citation>
    </citation> 
    <citation key="key-10.9876/S0003695199034166-2">
    <unstructured_citation>String 2/unstructured_citation>
    </citation> ......


    At the moment there is no output. [[*tv.art_lit]] works, and displays a list like <ul> <li> ... </ li> <li> ... </ li> ... </ ul>.

    doiCititationList:
    $tv_param = array(
            'contentid' => $id // also trying $resourceId
          , 'tmplvarid' => 11 // art_lit id, also trying $tvId
        );
    $tvx = $modx->getObject('modTemplateVarResource', $tv_param);
    $artlit = $tvx->get('value');
    $str = str_replace(array('<li>', '</li>'), array($tvr.'<unstructured_citation>', '</unstructured_citation></citation>'), $artlit);
    return $str;


    As I understand it, the snippet does not determine the ID of the articles in the container, but instead uses the ID of the final page of the template output. What could be the problem? Thanks in advance!
      • 3749
      • 24,544 Posts
      That's the expected behavior.

      You need to send the resource id as a property to the doCitationList snippet. Because you're calling it more than once, the snippet tag should also be uncached or you'll only get the output of the first execution repeated over and over:

      [[!doCitationList? &docId=`[[+id]]' ]]


      Then in your snippet:

      $docId = $modx->getOption('docId', $scriptProperties, '');
      
      $tv_param = array(
          'contentid' => $docId, 
          'tmplvarid' => 11 // art_lit id (this is fine)
      );
      
      $str = 'TemplateVarResource not found';
      
      $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);
      }
      
      return $str;
      
      


      It may not work because of nesting/cache issues, but I think it will.

      FYI, this method won't work if the TV is set to its default value. In that case there's no modTemplateVarResource record.
        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
        Yep, receiving TemplateVarResource not found. Cleared cache - same. Where located default value? [ed. note: extrim25 last edited this post 9 years ago.]
          • 3749
          • 24,544 Posts
          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';
              }
          }
            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
            Nothing. No output.
              • 3749
              • 24,544 Posts
              You still have return $str at the end, right?
                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, current snippet:

                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
                  That's not the whole snippet, is it? I meant to add that code to your existing snippet. So the whole snippet would look like this:


                  $docId = $modx->getOption('docId', $scriptProperties, '');
                   
                  $tv_param = array(
                      'contentid' => $docId, 
                      'tmplvarid' => 11 // art_lit id (this is fine)
                  );
                   
                  $str = 'TemplateVarResource not found';
                   
                  $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;
                    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
                    In this case also blank output. Maybe I can PM you with site details, or there is something that I can forget about? [ed. note: extrim25 last edited this post 8 years, 11 months ago.]
                      • 3749
                      • 24,544 Posts
                      I made a typo in the tag. It should be:

                      [[!doCitationList? &docId=`[[+id]]`]]


                      Be sure the snippet is called doCitationList.
                        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