Plugin

Archived
Forum
(read-only)

String

ExpressionEngine 1.x, ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From eMarketSouth

     

Can’t pull parent data within custom field?

Support Request

Biggles
Biggles

Hi,

I’m using a category e.g. /mysite.com/directory/category/cars

The Parent channel entry “company” holds all the category/company info and then it has a relationship with the child “offers”

So on this category page I want to show all the “car Offers”... fine…

Because the category indicator is used with the “company” channel I have to use “reverse_related_entries” to pull all the car info….

I have a conditional that says if the offer has an image…“show it” - if not “Show the company logo” - So my problem is I need to refer back to the parent “company” to grab the url of the logo…

Now i’ve tried this using your script, but I can’t get it to work…. I wonder if you can assist…

The relationship field within “offers” to the company is “offer-company”

& the custom logo field within “company” is called “company-logo”


Here’s my code:

{exp:channel:entries channel="company" limit="50"}
{reverse_related_entries channel
="car"

{title}
{if car
-image}
    {exp
:imgsizer:size src="{car-image}" width="80" height="80" remote="on"}
        
<img src="{sized}" width="{width}" height="{height}" />
    
{/exp:imgsizer:size}
{if
:else}
    {exp
:string:set name="offer-company" random}
        {exp
:imgsizer:size src="{company-logo}" width="80" height="80"}
            
<img src="{sized}" width="{width}" height="{height}" alt="" />
        
{/exp:string:set}   
    {
/related_entries}
{
/if}

{
/reverse_related_entries}
{
/exp:channel:entries} 

Hope you can assist.

eMarketSouth
# 1
Developer
eMarketSouth

Hello Biggles,

It looks like you’re using {exp:string:set} inside your {reverse_related_entries} block when it should be used outside. There’s an example on our website similar to what you’re trying to accomplish.

Your code should look something like:

{exp:channel:entries channel="company" limit="50"}
{exp
:string:set name="company-logo" random}{company-logo}{/exp:string:set}
{reverse_related_entries channel
="car"

{title}
{if car
-image}
    {exp
:imgsizer:size src="{car-image}" width="80" height="80" remote="on"}
        
<img src="{sized}" width="{width}" height="{height}" />
    
{/exp:imgsizer:size}
{if
:else}
    {exp
:imgsizer:size src="{exp:string name="company-logo" random}" width="80" height="80"}
        
<img src="{sized}" width="{width}" height="{height}" alt="" />
    
{/exp:imgsizer:size}
{
/if}

{
/reverse_related_entries}
{
/exp:channel:entries} 
Biggles
# 2
Biggles

Thanks,

I now understand how it all works, so thank you for that.

There is a problem though… (Sorry!)

{exp:string name="company-logo" random} 

This pulls the correct path of the logo fine, but if you use your grab within the image resizing, it seems to just print the path on the page e.g. www.mysite.com/logo/carlogo.png ....

{exp:imgsizer:size src="{exp:string name="company-logo" random}" width="80" height="80"}
    
<img src="{sized}" width="{width}" height="{height}" alt="{title}" /> 
{/exp:imgsizer:size} 

Any ideas? - as if I just use a basic:

<img src="{ exp:string:set name=" /> 

it works…

eMarketSouth
# 3
Developer
eMarketSouth

The imgsizer plugin appears to be evaluating before company-logo is set.  That’s not a problem with imgsizer, but a result of the the way EE works with template tags.  There’s a couple workarounds you can try:

Add a “parse=inward” parameter to the {exp:channel:entries} tag to change the tag parse order.  More information on parse=inward is available here.

Move the {if} block to a separate template and include it with an {embed} tag.  That forces imgsizer to run after {exp:channel:entries} and {exp:string:set}