We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31410
    • 66 Posts
    Hi
    i was trying to export some pages data to csv or pdf files
    the exported data includes some tvs too but few pages have tvs value and other pages have any values for data
    but when i try to loop through the data using getChunk those empty/unset tv placeholders still showing as tags instead of empty values
    ex: mychnkk for csv
    [[+menutitle]],[[+pagetitle]],[[+tv.course_start_date]],[[+tv.course_end_date]],[[!+tv.venuename]],[[+tv.cf]]


    my snippet call to loopthough
    $output.=$this->modx->getChunk($tpl,$resourceArray)."\n";


    and the output of each iteration is
    123456,bbmmmmmmmmmmm,[[+tv.course_start_date]],[[+tv.course_end_date]],[[!+tv.venuename]],"Financial"


    i understand those tvs have not set for some resources and modx still waiting to set placeholders for this empty placeholders

    but how i can simply igonre those empty placeholders if its not set for a resource.we have many tvs associted with a resource so its not possible to check if a placeholder/tv is empty or not and client will change the chunk with any new tvs
    tried parsechunk but its throwing errors with some array to string conversion (the pages are CR so it have some properties too)
    i appreciate any help here

    Thanks
    Venu
      • 3749
      • 24,544 Posts
      Those placeholders should disappear when the page is rendered unless they're being turned into htmlentities somewhere.

        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
        • 31410
        • 66 Posts
        Thanks Bob

        but its not a typical page rendering
        the page have a form which allow user to select the fileformat,course list etc
        so when the form is submitted it will export the results to a file and send the user to that file
        if (empty($data)) return $this->generateDownload();
        see how i save data
        //when the form submitted and results rendered as $data
        forloop(){
        ....
        $data.=$this->modx->getChunk($tpl,$resourceArray)."\n";
        }
                $fileName = $this->modx->getOption('core_path').'export/schedule/'.$f.'.'.$type;
        
                /** @var modCacheManager $cacheManager */
                $cacheManager = $this->modx->getCacheManager();
                $cacheManager->writeFile($fileName,$data);
        ....
                return $this->modx->sendRedirect($this->modx->makeUrl($this->getProperty('downloadPage')).'?file='.$fileName .'&type=csv');
        ....

        i hope this will give you idea on how it works
        the results are not rendered for page output but to save it to file and send the user to the file location
        so any alternatives for getChunk to make this work?

        Thanks

          • 4172
          • 5,888 Posts
          you can make sure, that all fields have a value:

          <?php
          
          $allFields = 'menuetitle,pageitle,tv.course_start_date,tv.course_end_date,tv.venuename,tv.cf';
          
          foreach ($allFields as $field) {
              $defaultValues[$field] = '';
          }
          
          
          foreach ($collection as $object) {
              //....
              $resourceArray = array_merge($defaultValues, $resourceArray);
              $data .= $this->modx->getChunk($tpl, $resourceArray) . "\n";
          }


          you could probably also use $modx->getParser() and $modx->parser->processElementTags(........) with removeUnprocessed - flag
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 31410
            • 66 Posts
            Bruno and Bob
            Thank you for the help
            aray merge with some predefined fields wont work in my case as client keep adding extra Tv's and place it in chunk himself in later stage

            but the getParser and processElementTags functions did what i wanted to do .i have seen those functions b4 but thought those are deprecated Thanks for reminding

            if anyone want to have similar results use those functions after getChunk call when you finish rendering results
            $output=$this->modx->getChunk($outerTpl,$yourresultArray);
            $this->modx->getParser();
            /*parse all non-cacheable tags and remove unprocessed tags if you want to parse cacheable tags set 3 param as false*/
            $this->modx->parser->processElementTags('', $output, true, true, '[[', ']]', array(), $counts);


            Thanks again guys iam more of commercial guy who never replied to others questions but you changed my thinking with quick replies

              • 3749
              • 24,544 Posts
              I'm glad you got it sorted. Thanks for reporting back. smiley
                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