A
A
Alexander Ivanov2016-11-14 17:44:11
PHP
Alexander Ivanov, 2016-11-14 17:44:11

How to display the tv value of a context resource in a snippet?

So I get the data of a specific tv in the snippet.
$modx->resource->getTVValue('weneed');
full code and purpose of the snippet (calculate percentages):

<?php
$priceHave =  $modx->resource->getTVValue('wehave');
$priceNeed =  $modx->resource->getTVValue('weneed');
$procent=$priceNeed/100;  
$result=$priceHave/$procent;
echo round($result,2);

The problem is that it works only on the main page, and does not count on other pages for obvious reasons.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Andreev, 2016-11-14
@cimonlebedev

$resource = $modx->getObject('modResource', $resourceId);
$priceHave =  $resource->getTVValue('wehave');
$priceNeed =  $resource->getTVValue('weneed');
......

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question