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

    I’m trying to figure out how to get the document id from the snippet inside the ditto template.


    Here is my Ditto template:

    <div class="ctv_thumb"><a href="[~[+id+]~]" class="[[Video_Style]]"><img src="/images/spacer.gif" border="0" width="150" height="125" alt="[+pagetitle+]"></a><img src="[+Video_Thumb_SML+]" width="150" height="100" border="0" alt="[+pagetitle+]" /><h1>[+pagetitle+]</h1></div>
    


    The snippet: [[Video_Style]] contains the PHP which checks if you are currently on that particular document based on the parameter ’x’ in the url, ex: http://domain.com/index.php?x=3456

    <?php
    $id = $modx->documentIdentifier;
    $currentid = $_GET['x'];
    
    if (($currentid != '$id') || ($currentclass == '')) {
    $thumbclass = "ctv_link";
    }
    else {
    $thumbclass = "ctv_link_active";
    }
    
    echo $thumbclass;
    ?>


    since its being run at the document level i get the wrong id at this line: $id = $modx->documentIdentifier;

    i search the forums and found this solution on how to grab a document id at the template level:

    $docID = (isset($docID)) ? $docID : $modx->documentIdentifier;
    $newID=$modx->getTemplateVarOutput('id',$docID);


    For some reason it gives me back an ’array’.
    Can anybody point out any obvious errors ?


    Thanks!

    Aleks
      MODx Revo 2.0.6-pl (Traditional) | Apache 2.2.3 | PHP 5.2.14 | MySQL 5.0.77 | MAC OS 10.6.5 | FF 3.6/Chrome 9.0.5
      • 2690
      • 148 Posts
      [SOLVED]


      here is the final snippet call:
      <?php
      $docID = (isset($docID)) ? $docID : $modx->documentIdentifier;
      $currentid = $_GET['x'];
      
      if (($currentid != $docID) || ($currentid == '')) {
      $thumbclass = "ctv_link";
      }
      else {
      $thumbclass = "ctv_link_active";
      }
      
      echo $thumbclass;
      ?>


      + a correct snippet call: [[Video_Style?&docID=`[+id+]`]]
        MODx Revo 2.0.6-pl (Traditional) | Apache 2.2.3 | PHP 5.2.14 | MySQL 5.0.77 | MAC OS 10.6.5 | FF 3.6/Chrome 9.0.5