Catalogue rating within custom templates
Posted
#5050
(In Topic #1130)

Standard member

I added the rating block into the template, like so:
{$BLOCK,block=main_rating}
This allowed me to rate the entry but it was not saved when I refreshed the page. So I gave the block a name (it names itself with the title of the catalogue entry, which is also the name of the current page being viewed), which seems to keep the rating:
{$BLOCK,block=main_rating,page=h_{$LCASE,{FIELD_0}}}
A {RATING} param is passed into the templates but seems to always remain empty. Oddly though, it returns blank but not empty when I do something like this:
{+START,IF_NON_EMPTY,{RATING}}{RATING}{+END}
I was hoping to use this parameter to display the entry's overall rating (if that's even what it's intended for). Since I couldn't get it to show any value, I looked into using {$RATING}, like so:
{$RATING,catalogue_entry,{ID}}
This always returns 0. I assume the rating block is not communicating with the entry's actual rating, or maybe I'm using the wrong parameters within {$RATING}.
Also, are there any parameters I can pass into {$BLOCK} to hide the outer box styling of the main_rating block, and only show the star display + number of votes?
Posted

Site director

https://github.com/ocproducts/composr/commit/36efb46970672a19470c20f65fe2b02fdb6d3138
Ignore the string_scan.php file.
I think your 'not saving' issue is due to your page names being something non-ID-like (e.g. some slightly unusual character), which the block didn't expect.
I've added a display_tpl block parameter which you can set to RATING_INLINE_DYNAMIC.
I think your catalogue is showing no rating because it doesn't have ratings enabled on the entry(ies).
And IF_NON_EMPTY will not consider something with just whitespace as empty. For that you need to do IF_NON_EMPTY,{$TRIM,...}. I think in the case of ratings the templating controls the various situations where rating is available or not, and templates will often introduce white-space.
Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
1 guest and 0 members have just viewed this.