Quick question regarding the viewing format from a ditto call.
I got the star rating working fine, the votes are being counted and showed in the ditto call for each page, but the format is in text.
4:1 (a rating of 4 with 1 vote) for example.
What parameter can I add to the ditto template chunk to get a more visually friendly vote rating/count to be displayed, but not voted on?
The parameters on the snippet download page don’t seem to be what I need.
Sorry for coming a little late to the party(like 4 years late
),but only recently i found myself in a similar situation and i kinda found a soloution. Not a preferable one,but it works.
1)First, create a snippet called Rating
2)Paste the following code:
<?php
$myVar = $modx->getTemplateVarOutput(array("star_rating"),$docID,$published=1);
$explode = $myVar['star_rating'];
$rating = explode(":", $explode);
if($rating[1]!=0){
$unrounded=$rating[0]/$rating[1];
}
else{
$unrounded=null;
}
$output=round($unrounded,2);
return $output;
?>
3)On your articles, call it like this where you want the rating value to display
The steps above are only for displaying a rating on your articles. If you want ditto to take this rating and display it on another page(like where you display all articles for example on a news page),you will need to do the following:
4)Download and install the PHx plugin:
http://modx.com/extras/package/phx
5)Go inside your phx directory-->modifiers and make a custom modifier called tv.phx.php (originally from natalino) and paste this code:
<?php
if(strlen($options )>0) {
$data = explode("?",trim($options),2);
$id= (!empty($data[0]) && is_numeric($data[0])) ? $data[0]: '';
$tv= (!empty($data[1])) ? $data[1]: '';
$result = $modx->getTemplateVar($tv, 'name', $id, 1);
$rating=explode(":",$result['value']);
if($rating[1]!=0){
$unrounded=$rating[0]/$rating[1];
}
else{
$unrounded=null;
}
$output=round($unrounded,2);
return $output;
}
?>
6)Make the page where you will have your ditto call uncacheable(in the manager, edit the page,press settings and then untick the "Cacheable" checkbox).
7)In your ditto tpl call the tv like this:
[+phx:tv=`[+id+]?star_rating`+]
8)
is the default tv used by the css rating snippet.If you have changed the name of your tv, then you should replace all instances of
with the name of your tv(both in the tv.phx.php modifier and the rating snippet).
Final thoughts: If someone manages to do that with all-in one snippet,then that will be the best option. PHx itself is slower than a snippet and having to make the page, where you have the ditto call, uncacheable will take its toll on loading times. Especially in the event that you have a lot of articles to display.