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

    I have a template called ap-Publication, which has a TV called apPubBuy (Input Type = Text and Default Value="Not Available").


    I use a snippet called apGetPubDetails to read the value of the TV and then output a string based on the TV value. Code given below...

    //define place holders
    $buyOnline='';
    
    //-- fetch the document's current id.
    $currentID = $modx->documentObject['id'];
    
    // fetch the TV $apPubBuy output and store it in $valueLink.
    $valueLink = $modx->getTemplateVarOutput($apPubBuy, $currentID, 1);
    
    //check if apPubBuy != 'Not Available'
    if($valueLink['apPubBuy'] && $valueLink['apPubBuy'] != 'Not Available') {
    	//make HTML output
    	$buyOnline = '<a href="'.$valueLink['apPubBuy'].'" title="[*pagetitle*]" rel="external">'.$valueLink['apPubBuy'].'</a>';
    }
    else {$buyOnline=$valueLink['apPubBuy'];}
    
    //-- output to placeholders
    $modx->setPlaceholder('buyOnline', $buyOnline);


    Below is how I call it in the Chunk
    [!apGetPubDetails!]
    <dt>Buy Online</dt>
    	<dd>[+buyOnline+]</dd>


    The above code works fine for (first 20 of the total TVs the website contains). All TVs defined after the 20th TV I have created return NO value "BLANK" with th above code.

    But when I output the TV using [*apPubBuy*] it outputs the TV content e.g. "Not Available".

    Using the same code above if I replace t]he apPubBuy with apBodyID (which is the first TV I created of TEXT input type) it shows the value of the TV.

    Is this a bug or am I doing something wrong here?

    Has anyone ever faced this problem?

    -raavi
    • Try returning something meaningless in the value instead of empty strings (i.e. <!--no value-->). I believe the problem is PHP tries to assign an empty string to the $valueLink[’apPubBuy’], which evaluates to false. So when you test the variable...
      if($valueLink['apPubBuy'] ... 

      ...that evaluation fails as expected. You might try using this also, instead of the meaningless value
      if (isset ($valueLink['apPubBuy']) && ....
        • 24278
        • 165 Posts
        Opengeek,

        I tried it but it still DOES NOT return any value. I also tried echoing the value of $apPubBuy as under...

        //define place holders
        $buyOnline='';
        
        //-- fetch the document's current id.
        $currentID = $modx->documentObject['id'];
        
        // fetch the TV $apPubBuy output and store it in $valueLink.
        $valueLink = $modx->getTemplateVarOutput($apPubBuy, $currentID, 1);
        echo "valueLink=".$valueLink['apPubBuy'];


        But it shows valueLink=
        Nothing gets returned.

        -raavi
          • 24278
          • 165 Posts
          If I replace apPubBuy with ap-eventsTime (which is the 20th TV of all the website TVs I have created)....
          it returns exactly as desired i.e. "Not Available" when nothing is entered and 9:30 to 16:30 when I entered the same.

          //-- fetch the document's current id.
          $currentID = $modx->documentObject['id'];
          
          // fetch the TV $ap-eventTime output and store it in $value.
          $valueLink = $modx->getTemplateVarOutput($ap-eventTime, $currentID, 1);
          
          echo "valueLink=".$valueLink['ap-eventTime'];


          -raavi
          • Ok, I guess I misunderstood the problem the first time (sorry).

            I looked for any code that might cause this and the only things that raised any flags with me were the possibility that you might not have the proper template specified for those document with permission to access that tv, or some permissions on those documents were excluding those documents altogether. Are either of these possible?

            If not, you could try outputting something like this in your snippet for testing...

            echo print_r($valueLink, true);


            to see the full contents of the array being returned.
              • 24278
              • 165 Posts
              Hi,

              Tried your suggection mentioned above, but it returned nothing. The template association is correct for the document and when I use [*apPubBuy*] within the document it outputs the correct value of the TV.

              Only when I try and check the value inside the shippet using my code above does it return nothing.

              I am confused and stuck huh

              -raavi

              Added Later

              In my snippet when I replace the TV apPubBuy with the TV ap-bodyID, this is what your suggestion echo print_r($valueLink, true); returns...

              Array ( [ap-bodyID] => story [ap-thumbnail] => thumbnail **shows image**  [ap-contributorsList] => 61 [apPubAuthor] => Phaidon Press [apPubISBN] => 7666754563214 [apPubHouse] => Phaidon Press [apPubDate] => April 2006 [apPubBuy] => Not Available [alias] => pahidon-design-classic [cacheable] => 1 [content] =>
              
              Phaidon Design Classics is a magnificent source book on design with precise information about each product, its designer, its manufacuture and their history. The 999 objects here have been selected by a panel of experts that includes designers, architects, auctioneers, critics, curators, journalists and academics.
              [contentType] => text/html [content_dispo] => 0 [createdby] => 1 [createdon] => 1147576409 [deleted] => 0 [deletedby] => 0 [deletedon] => 0 [description] => Phaidon Design Classics' three volume set contains the most comprehensive collection of design classics and features the most innovative and beautiful products created in the last 200 years [donthit] => 0 [editedby] => 1 [editedon] => 1147715780 [haskeywords] => 0 [hasmetatags] => 0 [hidemenu] => 1 [id] => 72 [introtext] => Phaidon Design Classics' three volume set contains the most comprehensive collection of design classics and features the most innovative and beautiful products created in the last 200 years. [isfolder] => 0 [longtitle] => Phaidon Design Classics 3 volume set [menuindex] => 0 [menutitle] => [pagetitle] => Phaidon Design Classic [parent] => 13 [privatemgr] => 0 [privateweb] => 0 [pub_date] => 0 [published] => 1 [publishedby] => 1 [publishedon] => 1147577963 [richtext] => 1 [searchable] => 1 [template] => 13 [type] => document [unpub_date] => 0
              • Hmmm, this is odd, what is the value you are passing as the first parameter to getTemplateVarOutput() in this statement...

                $valueLink = $modx->getTemplateVarOutput($ap-eventTime, $currentID, 1);


                $ap-eventTime should really be ’*’ if you want all the template variables returned, and just the string ’ap-eventTime’ if you just want to retrieve one template var. I’m just not sure what the value of $ap-eventTime is, but I imagine that is related to the issue.
                  • 24278
                  • 165 Posts
                  grin sorry,

                  It is a string. It works fine now. I guess I got too confused with this issue that I did not check the obvious error at my end. (this waht happens when you do tooooo many things at one time)

                  I am really sorry I wasted quite a bit of your time. I appreciate your patience and willingness to help.

                  I hope I dont come up with such stupid queries in future.

                  Thanks once again. You are the best.

                  -raavi