1

I'm using Solspace Rating to let users rate and review entries. I have many different channels and each channel has their own rating sub-category names saved as global variables. For example, for the channel "Venues" I have global variables like {venue_1label}, {venue_2label}, {venue_3label}, {venue_4label} for the names of the 4 rating subcategories. You can see an example of this here: http://www.weddingwise.co.nz/vendor/kumeu-valley-estate#h1-reviews. On the right side of each review there are 4 sub-ratings below the overall rating. Every channel has a different set of sub-rating labels.

These global variables use the {channel_short_name} of the rated entry as part of the variable name, so when I'm displaying the ratings on a single entry page I pass the {channel_short_name} through an embed and then use it to assemble the global variable tag name like this:

{exp:channel:entries status="Open|Featured"}
{embed="includes/review" entry_id="{entry_id}" channel_short_name="{channel_short_name}"}
{/exp:channel:entries}

And then the embed template "includes/reviews" includes pieces like this:

<span class="label">{{embed:channel_short_name}_1label}</span>

Which parses to {venue_1label} and then is replaced by the corresponding global variable by the same name.

This all works fine. My problem is now displaying the same information on a different page.

I'm listing all Ratings by the logged in user on a user profile page. For this page the {exp:rating:entries} tag is not on a single entry page and not inside {exp:channel:entries}. So I need to use the {rating_id} to find the matching {entry_id} of the associated rated entry, and then use that {entry_id} to pull {channel_short_name}, and then use that {channel_short_name} to build the global variable tag like I did above through an embed.

I can't get this to work!

I've tried using 2 levels deep of embedded templates combined with an SQL query to grab the {entry_id}. First get {entry_id} and pass as embed variable to first embed template. Inside first embed template use {exp:channel:entries} to get {channel_short_name} from {entry_id}, then pass {channel_short_name} to another embed template. That second level embed template then uses {channel_short_name} embed variable to assemble the final global variable tag.

This works for some channel names, but for some reason other channels are not working. I can't find any different between the channels that would cause one to work and not another.

There must be a much less convoluted way to achieve this?

1

I'm assuming the goal is to get the channel_short_name to use in your global variable. An SQL query might be the quicker way to get to this value, and would avoid using embeds which hinder performance.

For example, this query might help:

{exp:query sql="SELECT ch.channel_name AS channel_short_name 
  FROM exp_ratings r
  LEFT JOIN exp_channels ch ON ch.channel_id = r.channel_id
  WHERE r.rating_id = {rating_id}"
}
    {channel_short_name}
{/exp:query}

Then, you can pass {channel_short_name} in your embed to build your global variable.

| improve this answer | |
  • Thanks for the reply. I will try to test this out today. – Benek Lisefski Aug 1 '13 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.