We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17422
    • 225 Posts
    I use a snippet with chunk and TV :

    in my chunk, i need a placeholder title and other.

    How pass placeholder title or longtitle in my chunk.

    $items = $modx->fromJSON($outputvalue);
    $chunk = $modx->getObject('modChunk', array ('name'=>$tpl));
    $template = $chunk->getContent();
    foreach ($items as $item)
            {
                $chunk = $modx->newObject('modChunk');
                $chunk->setCacheable(false);
                $output .= $chunk->process($item, $template);
            }
    
      • 4172
      • 5,888 Posts
      you want to add additional fields to them which are coming from jsoned $outputvalue?
      where are they coming from?
      do you have an example for us?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 17422
        • 225 Posts
        yes i need to add additional fields to them which are coming from jsoned $outputvalue.

        exemple

        in my chunk, i need a placeholder title and longdesc and other to my resource

          • 4172
          • 5,888 Posts
          I’m trying to understand what you are after. But, sorry, I don’t.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 17422
            • 225 Posts
            in my chunk i have :
            <li>
                <a href="[[+url]]" title="[[+title]] - [[+nom]]">[[+url]]</a>
            </li>​
            


            [[+url]] and [[+nom]] are values of my tv with multiitemsGrid

            and [[+title]], is the title of my resource.

            but with the snippet i pass just the tv values not the title of my resource, i don’t know how to do this.

            in below my snippet.

            <?php
            $tvname = $modx->getOption('tvname', $scriptProperties, '');
            $tpl = $modx->getOption('tpl', $scriptProperties, '');
            $docid = $modx->getOption('docid', $scriptProperties, $modx->resource->get('id'));
            
            if ($tvname == '' || $tpl == 'xx')
            {
                return;
            }
            $tv = $modx->getObject('modTemplateVar', array ('name'=>$tvname));
            $outputvalue = $tv->renderOutput($docid);
            $items = $modx->fromJSON($outputvalue);
            $chunk = $modx->getObject('modChunk', array ('name'=>$tpl));
            $template = $chunk->getContent();
            $output = '';
              if (count($items) > 0) {
            switch ($tvname) {
            case DatesConcerts:
            $output .= '<ul class="DatesConcerts">';
                break;
            case Discographie:
            $output .= '<ul class="Discographie">';
                break;
            case Galerie:
            $output .= '<ul class="Galerie">';
                break;
            case UrlSiteArtiste:
            $output .= '<ul class="SitesArtiste">';
                break;    
            }    
                    foreach ($items as $item)
                    {
                        $chunk = $modx->newObject('modChunk');
                        $chunk->setCacheable(false);
                        $output .= $chunk->process($item, $template);
                    }
                  $output .="</ul>";
                }
              
              return $output;​​​​​​
            
              • 4172
              • 5,888 Posts
              I’m still not sure, but you can add the docid to placeholders:

              <?php
              $tvname = $modx->getOption('tvname', $scriptProperties, '');
              $tpl = $modx->getOption('tpl', $scriptProperties, '');
              $docid = $modx->getOption('docid', $scriptProperties, $modx->resource->get('id'));
              
              if ($tvname == '' || $tpl == 'xx')
              {
                  return;
              }
              $tv = $modx->getObject('modTemplateVar', array ('name'=>$tvname));
              $outputvalue = $tv->renderOutput($docid);
              $items = $modx->fromJSON($outputvalue);
              $chunk = $modx->getObject('modChunk', array ('name'=>$tpl));
              $template = $chunk->getContent();
              $output = '';
                if (count($items) > 0) {
              switch ($tvname) {
              case DatesConcerts:
              $output .= '<ul class="DatesConcerts">';
                  break;
              case Discographie:
              $output .= '<ul class="Discographie">';
                  break;
              case Galerie:
              $output .= '<ul class="Galerie">';
                  break;
              case UrlSiteArtiste:
              $output .= '<ul class="SitesArtiste">';
                  break;    
              }    
                      foreach ($items as $item)
                      {
                          $item['docid']=$docid;
                          $chunk = $modx->newObject('modChunk');
                          $chunk->setCacheable(false);
                          $output .= $chunk->process($item, $template);
                      }
                    $output .="</ul>";
                  }
                
                return $output;​​​​​​


              then you can use the snippet getResourceField for example with:


              <li>
                  <a href="[[+url]]" title="[[!getResourceField? &id=`[[+docid]]` &field=`pagetitle`]] - [[+nom]]">[[+url]]</a>
              </li>​


              Is it that, what you mean?

              Of course, you can also get the resourceFields in your snippet with
              $object=$modx->getObject('modResource',array('id'=>$docid));
              and put its values the same way I did with $docid to the placeholders.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 17422
                • 225 Posts
                Thanks Bruno,

                i use getObject in my snippet and work fine.

                How is the best performing ? via getObject or via snippet getResourceField

                Laurent

                  • 18373 ☆ A M B ☆
                  • 3,141 Posts
                  Are you asking how to fill the placeholders with values? Or what else?
                    Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                    Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                    • 17422
                    • 225 Posts
                    my question is what object (in snippet or in chunk with getressourceField) requires the least resource for the server?

                      • 18373 ☆ A M B ☆
                      • 3,141 Posts
                      Using the objects in snippets probably uses slightly less resources since it wont have to process the chunk as well.
                        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.