We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26074
    • 121 Posts
    Site structure is:
    News (3)
    |____News numero 1 (4)
    |____News numero 2 (6)
    


    I have created 3 TV for my template to use with Ditto:
    titolo -> Input Type=Text area
    immagine -> Input Type=Image
    descrizione -> Input Type=Text area (mini)

    Then I created the chunk template_news for Ditto call
    <h1>[+tvtitolo+]</h1>
    [[verifica]]
    <p>[+tvdescrizione+]</p>
    


    The snipper [[verifica]] is a check for TV immagine. If is present return the HTML image tag else return nothing.
    <?php
    $output='';
    $idimmagine=$modx->getTemplateVarOutput('immagine',$modx->documentIdentifier);
    if($idimmagine['immagine']!='') $output.='<img src="' . $idimmagine['immagine'] . '" />';
    return $output;
    ?>
    



    In the News page (id=3) I call:
    [[Ditto? &tpl=`template_news` &startID=`3` &summarize=`3` ]] 
    


    Now the problem is in the snippet [[verifica]] on the parameter $modx->documentIdentifier
    It return 3 (id of page/container News) and don’t show the image that I have inserted in TV, but I want that it return 4 for first news, 6 for second news, etc...

    How I make this loop in php? Is possible?

      ___________________________________________________________________
      ..:: Samuele ::..
      • 11975
      • 2,542 Posts
      Ciao,

      you have to change the code of your snippet to pass the id parameter

      [[verifica? &docid=`[+id+]`]]

      $id = (isset($docid)) ? $docid: false;
      $output='';
      if(is_numeric($id)){
      $idimmagine=$modx->getTemplateVarOutput('immagine',$id);
      if($idimmagine['immagine']!='') $output.='<img src="' . $idimmagine['immagine'] . '" />';
      return $output;
      }
      


      :-)
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 26074
        • 121 Posts
        Thanks heliotrope, it is that I want. smiley
          ___________________________________________________________________
          ..:: Samuele ::..
          • 11975
          • 2,542 Posts
          You’re welcome.

          The new version (2.0) of ditto will supports PHx so you won’t have to use anymore your own snippet to check if the Tv has a value.

          Your tpl chunk will look something like this



          <h1>[+titolo+]</h1>
          [+immagine:isnot=``:then=`[+immagine+]`+]
          <p>[+descrizione+]</p>

          That will reduce the required db queries

          :-)
            Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
            • 26074
            • 121 Posts
            I don’t know PHx. I will try later.
              ___________________________________________________________________
              ..:: Samuele ::..