We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40609
    • 2 Posts
    hy there, i'm new here and a beginner with MODx.

    I have big trouble with a phx, TV's and YAMS.

    My problem:

    I have 3 File upload TV's called pdf_de, pdf_en. pdf_th.
    The PDF's should be show, if TV pdf_de or pdf_en or pdf_th has a value, if not: show nothing.

    My solution:

    [*phx:if=`[[YAMS? &get=`data` &from=`pdf` &docid=`[*id*]`]]`:isnot=``:then=`yes`:else=`no`*]

    Another solution with a snippet:

    <?php
    $tv_row = $modx->getTemplateVar('pdf');

    if(!empty($tv_row['value'])) echo '<h2><a href="[[YAMS? &get=`data` &from=`pdf` &docid=`[*id*]`]]">PDF Download</a></h2>';
    ?>

    but nothing happens. sad

    Is there a solution for this?

    -> Sorry for my bad english



      • 36404
      • 307 Posts
      hi,

      as apparently, you're using yams and phx, i think we'll have many occasions to speak here smiley

      this would have some more chance to work
      <?php
      // initialize what you're going to return
      // start with something empty
      $chtml  = '';
      // this retreives the language you're viewing the site with
      $yams   = YAMS::GetInstance();
      $langId = $yams->GetCurrentLangId();
      // get the right tv
      $zitv   = 'pdf_' . $langId;
      $tvs    = $modx->getTemplateVarOutput(array($zitv), $docid, $published=1);
      // return something or not
      if ( $tvs != false && $tvs[$zitv] != '' )
      {
      	$pdf    = $tvs[$zitv];
      	$chtml .= '<h2><a href="' . $pdf . '">PDF Download</a></h2>';
      }
      return $chtml;
      ?>


      assuming you've named the snippet "getpdf" for example, call it with
      [!getpdf? &docid=`[*id*]`!]

      where you want in the template, it should do the trick

      have swing

        réfléchir avant d'agir
        • 40609
        • 2 Posts
        Awesome

        Many thanks..it works perfectly!
          • 36404
          • 307 Posts
          my pleasure smiley

          you'll just have to implement a way to write "PDF download" in the right language, there are several ways to do this, including a little language files management i use and will give you of course if you needed it

          have swing
            réfléchir avant d'agir