We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29076
    • 615 Posts
    I have a spesific Template called Holiday with assigned TVs, call them singleRoom and doubleRoom. Those Vs are assigned to only that Template.

    In my SideMenu Chunk that runs on all pages, I need to run a snippet where I get the values from those TVs, even if they are not assignet to the Templates for the another resources. (The result should be the Sum of singleRoom and doubleRoom (in this case to show the total amount of available rooms.)

    So in a snippet: how can I get access to those TVs from that Resource?

    Setup:
    Revo 2.5.2pl
    Resource with Template called Holiday and TVs called singleRoom an doubleRoom.
    Chunk for SideMenu running on all pages with a snippet that gets the values from singleRoom an doubleRoom.

    I have this code, but it dosen't give the correct result:
    <?php
    $output = '';
    $value1 = $modx->resource->getTVValue('singleRoom');
    $value2 = $modx->resource->getTVValue('doubleRoom');
    
    if ($value1 == 0 && $value2 == 0) {
        $output = $modx->getChunk('AllFull');
    } else
    	$sum = $value1 + $value2;
    	$modx->setPlaceholder('TotalRooms', $_POST['TotalRooms']);
        $output = $modx->getChunk('AvailableRooms', $TotalRooms);
     
    return $output;

    This question has been answered by muzzstick. See the first response.

    [ed. note: Sylvaticus last edited this post 9 years, 10 months ago.]
      I think, thererfor I am! But what I am, and why...?
    • discuss.answer
      • 44195
      • 293 Posts
      The code you've got is getting the TV values directly from the currently active resource.
      If you want to get a value from a different resource you would need to know the resource id.

      e.g. something like:
      $otherResourceId = '521'; // for example
      $otherResource = $modx->getObject('modResource',$otherResourceId);
      $value1 = $otherResource->getTVValue('singleRoom');
      $value2 = $otherResource->getTVValue('doubleRoom');
      
        I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
        Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com
        • 29076
        • 615 Posts
        Thanks! smiley Works perfectly.
          I think, thererfor I am! But what I am, and why...?