We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24278
    • 165 Posts
    Dear Member,

    I have a TV call tv_bodyID which sets the <body id="value"> for each document that uses the template.

    How can I read the current document’s tv_bodyID in a snippet (based on the value of the tv_bodyID for the current document, a different chunk needs to be output).

    Even, a link to the tutorial will be very helpful.

    warm regards,

    -raavi
      • 24278
      • 165 Posts
      Dear Member,

      I am new to MODx and am a little confused at this point of time, I need help.

      My site structure
      -------------
      Under Site Start (root)
      |-home (document - uses template tpl_home)
      |-stories (folder - uses template blank)
      |-story 1 (document - uses template tpl_story)
      |-story 2 (document - uses template tpl_story)
      |-etc...

      My tpl_story has a TV called tv_thumbnail. To accept a thumbnail for each story.

      Can I show a list of all the latest posts on the "home page" using "NewsListing" even though my "home page uses a different template" as I have read that TVs are template specific and I havent assigned the TV "tv_thumbnail" to the template "tpl_home" as my home page on its own has no content.

      Hope I have been able to define my problem clearly. Need all the help I can use. There is infact more to it, but I want to get my basic understanding of MODx clear.

      Thanks in advance.

      -raavi.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I would think so, since the NewsListing is actually dealing with your news item pages it should be referring to TVs assigned to the news item templates.

        However, I’ve dealt with an issue involving template switchers, where I had to assign my TVs to the main template as well as the "switchable" template in order to be able to edit the TV for the page, since the document was initially assigned the main template, even though the main template never used the TVs. It didn’t hurt anything, the TV doesn’t show up on the page if it’s not called in the template being used.
          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
          • 24278
          • 165 Posts
          Thanks sotwell,

          I did use the NewsListing on the "home page template" as discussed above and it did a perfect listing as expected. MODx is SUPER COOL.

          I am now facing a new issue... can this be done?

          I have a snippet called checkDocID which checks the current doc’s ID and then outputs the correct NewListing call. This is what I have in my checkDocID snippet.
          if($modx->documentObject['id'] == 1)
          $outstring='[!NewsListing? &startID=`12,5,13` &summarize=`4` &multilevel=`1` &truncText=`Read More` &hidefolders=`true` &truncSplit=`false` &tpl=`listing` &dateformat=`%d,%b,%Y` &showarch=`false` &archplaceholder=`1`!]<hr />';
          elseif($modx->documentObject['id'] == 12)
          $outstring='[!NewsListing? &startID=`12` &summarize=`1` &multilevel=`1` &truncText=`Read More` &hidefolders=`true` &truncSplit=`false` &tpl=`listing` &dateformat=`%d,%b,%Y` &showarch=`false` &archplaceholder=`1`!]<hr />';
          
          return $outstring;


          But, instead of outputting the news items, it outputs the CODE as it is.

          What am I doing wrong?

          regards,

          -Raavi
            • 10487 MODX Staff
            • 1,535 Posts
            Hi Raavi, my guess is that the parser is not picking up the output in time to be able to render the output for the NewsListing calls.

            I would recommend using $modx->runSnippet() to get the output for the NewsListing and then output the results from your snippet above.

            Hope that helps, Garry
              Garry Nutting
              Senior Developer
              MODX, LLC

              Email: [email protected]
              Twitter: @garryn
              Web: modx.com
              • 24278
              • 165 Posts
              Dear garryn,

              You suggestion worked. Thanks a bunch.

              This is what I have in my checkDocID snippet. Is there a better way to do it?
              $snippetName= 'NewsListing';
              $snippetParams=array('summarize'=>4,
                                   'multilevel'=>1,
                                   'truncText'=>"Read More",
                                   'hidefolders'=>"true",
                                   'truncSplit'=>"false",
                                   'tpl'=>"ch-listing",
                                   'dateformat'=>"%d,%b,%Y",
                                   'showarch'=>"false",
                                   'archplaceholder'=>1,
                                   'emptytext'=>"No content available");
              
              
              if($modx->documentObject['id'] == 1){
              $docID="5,12,13";
              $snippetParams['startID'] = $docID;
              $outstring=$modx->runSnippet($snippetName, $snippetParams);
              return $outstring;
              }
              
              if($modx->documentObject['id'] != 1){
              $docID=$modx->documentObject['id'];
              $snippetParams['startID'] = $docID;
              $outstring=$modx->runSnippet($snippetName, $snippetParams);
              return $outstring;
              }
              


              There is one small issue, though... when the folder DOES NOT contain any documents "NewsListing" should return the value of the "&emptytext", but instead it retuns an ERROR, shown below...

              ERROR
              ====
              « MODx Parse Error »
              MODx encountered the following error while attempting to parse the requested resource:
              « PHP Parse Error »

              PHP error debug
              Error: array_values() [function.array-values]: The argument should be an array
              Error type/ Nr.: Warning - 2
              File: E:\xampp1.5.1\xampp\htdocs\ngo\manager\includes\document.parser.class.inc.php(691) : eval()’d code
              Line: 418


              Any, idea why is this happening.

              warm regards,

              -Raavi
                • 10487 MODX Staff
                • 1,535 Posts
                Hi Raavi, what version of NewsListing are you using? I’ve just checked your code with empty folders and works okay for me.

                The latest version of NewsListing is 6.4.2 and can be accessed here: http://modxcms.com/forums/index.php/topic,3873.0.html

                I think the error above was reported in previous versions (somewhere on the forum, can’t find the thread at the moment) so I’m wondering if the latest NewsListing release has fixed the problems.
                  Garry Nutting
                  Senior Developer
                  MODX, LLC

                  Email: [email protected]
                  Twitter: @garryn
                  Web: modx.com
                  • 24278
                  • 165 Posts
                  Thanks garryn for you prompt reply, I appreciate that.

                  I guess I will give NL 6.4.2 a go.

                  The members here at MODx are very helpful (and quick), thank you all once again for patiently answering all my problems.

                  warm regards,

                  -raavi.