We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1800
    • 52 Posts
    I got a simple question.

    I have a plugin that is  all built and working nicely.  What it does is count how many times a page is viewed (so i can make a list of popular pages in a ditto call) it does so by adding to a template variable.

    The plugin calls this template variable by its id.  I want to call it by the TV name so it will be easier to share with the community  (so people dont hae to edit the plugin)

    Right now the code looks like...
    $tmplvar = 16; // set this equal to the id of the template variable storing the count
    

    16 being the id of the TV.. i want it to be something like..
    $tmplvar = [*pageHits*]; // set this equal to the id of the template variable storing the count
    


    .. but i dont know the proper syntax, anyone know it  grin
      Minneapolis Web Design <-- where i work
      MODx Templates <-- new project im working on
      • 21257 MODX Staff
      • 730 Posts
      $tvname = 'ChildTemplate';
      $TV = $modx->getTemplateVar($tvname, 'id', $modx->documentObject['id'], $modx->documentObject['published']);
      
      echo "id of template variable $tvname is {$TV['id']}";
      


      Note, the last 2 parameters of the getTemplateVar function are the document id and the published status (0 or 1) of the document that you are retreiving the TV for. I just set it arbitrarily to the "current document" because I tested this inside a snippet.
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 1800
        • 52 Posts
        thanks for the help!
          Minneapolis Web Design <-- where i work
          MODx Templates <-- new project im working on