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

    I have followed the following post http://modxcms.com/forums/index.php/topic,8691.0.html and it works perfectly.
    I am using the following snippet:
    <?php
    //collect here your output in $output, use $modx->runsnippet or what else for generating your html-output.
    
    $doc['content']='<p>no docid was given to generate pdf-content</p>';
    if (isset($_GET['docid'])){
    $id=$modx->db->escape($_GET['docid']);
    $doc = $modx->getPageInfo($id,1,'content'); 
    $title = $modx->getPageInfo($id,1,'longtitle'); 
    
    }
    $output = "<h1>".$title['longtitle']."</h1><br/>".$doc['content']; 
    
    $basePath = $modx->config['base_path'];
    $pluginpath = $basePath.'assets/classes/tcpdf/';
    
    if ($_GET['contentType']=='pdf'){
    include $pluginpath.'examples/myexample.php';
    }
    else{
    	return $output;
    }
    ?>


    As can be seen is outputs the content, no problem but it also includes the following:
    {{dotted}}
    [*desc*]
    [[DocLink]]
    DOWN PDF

    How would i amend the above snippet to only output the content and [*desc*] (but i need the actual description and not [*desc*]

    I hope i’m making sense.

    Thank you
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Since MODx is not parsing this resource, the MODx tags in your resource content are being shown as-is. You’re going to have to fetch the fields you want yourself and pass them on to the PDF generator.

      Your snippet only fetches the content and the longtitle. If you want the description, you need to also fetch the description field.
      $doc = $modx->getPageInfo($id,1,'content'); 
      $title = $modx->getPageInfo($id,1,'longtitle');
      $desc = $modx->getPageInfo($id,1,'description');
      

      Then add it to your output wherever you want it.

      This line
      $id=$modx->db->escape($_GET['docid']);
      

      is not appropriate in this case; what you really need to do with the $_GET[’docid’] is make sure it’s numeric. GET values are always a string, so you can’t use is_int, but is_numeric will do fine. Probably best to just quietly fail if is_numeric returns false.
      if(!is_numeric($_GET['docid'])) { return; }


      http://php.net/manual/en/function.is-numeric.php


        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