Forum

Thread tagged as: Question, Problem, Shop

Multi Lingual with Categories: If Category match variable in Repeater

Hi Guys, I'm working on a multilingual website and using the new Shop !! (it's super Thanks !) I'm trying to allow the editor to have a single product with multiple languages, with the possibility of adding more. So I'm using Repeaters and assigning Categories to each element.

here's part of my product template:


<perch:repeater id="specifications" label="Specifications" divider-before="Specifications" help="Not dimensions, they are below"> <perch:shop type="text" id="specification_attribute" label="Attribute" /> <perch:shop type="text" id="specification_value" label="Value" /> <perch:categories id="lang" set="lang" label="Languages"> <perch:category id="catTitle" /> </perch:categories> </perch:repeater>

I'm using a different template to display the product info on the site and I'm passing a language variable into it called "userlang". So the part of my template looks like this:


<perch:repeater id="specifications"> <perch:if id="userlang" match="in" value="{catTitle}" case="insensitive"> <perch:shop type="text" id="specification_attribute" label="Attribute" /> <perch:shop type="text" id="specification_value" label="Value" /> </perch:if> </perch:repeater>

But I can't get it to match ? I've tried eq and i've tried reversing the id and values... I've tried wrapping the IF in <perch:categories tags, but that didn't work either.

I'm not sure if anyone else has tried this yet, but It would be super handy to get this working. Any suggestions ? Thanks Dylan

Dylan Rynhart

Dylan Rynhart 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

There's a few things here. Firstly you'll need to bring userlang into scope of the repeater (see "Accessing content outside the repeater": https://docs.grabaperch.com/docs/templates/repeaters/)

You'll also need to use perch:categories tags when dealing with anything in categories.

But more fundamentally, are you trying to categorise the items within the repeater? I'm not sure that's going to work how you think it will.

Thanks for your help, you might be right about it not working the way I think ! I'm really trying though, so here's my progress:

I'm trying this:


<perch:repeater id="specifications"> ??<perch:shop id="userlang" />?? <perch:categories id="lang" set="lang" label="Languages"> >><perch:category id="catTitle" /><< <perch:if id="userlang" match="eq" value="{catTitle}" case="insensitive"> <perch:shop type="text" id="specification_attribute" label="Attribute" /> <perch:shop type="text" id="specification_value" label="Value" /> </perch:if> </perch:categories> </perch:repeater>

I've put in the ?? and << to be sure of the output.

What I get is this:

??en?? >>en<< ??en?? >>fr<<

which is accounted for because I have two repeated Items. one set to english (en) and another to french (fr) and userlang is set to (en).

so it's not comparing them, but it is printing them correctly ? is it possible that I'm missing something from the If statement ?

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Try that scope-parent="true" on the <perch:categories> tag and then use parent.userlang

No, unfortunately it didn't work. Thanks though !

Is there anyway to show the variables that IF sees ?

it seems as though I can access both userlang and catTitle from the <perch:category with or without the scope change ?

Thanks a million Dylan

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok - so the userlang prints out ok within the perch:categories scope?

Ok, I got it working. I think this is basically that i didn't fully get the formatting of scope etc.. It was the <perch:shop that was wrong, the IF was working fine. This works and I think it's gonna be a great way of tagging content as being of one language or another, without having to have different products for different countries.

<perch:repeater id="specifications" >
    <perch:categories id="lang" set="lang" label="Languages" scope-parent="true">       
        <perch:if id="catTitle" match="eq" value="{userlang}" case="insensitive">               
            <perch:category type="text" id="parent.specification_attribute" label="Attribute" />
            <perch:category type="text" id="parent.specification_value" label="Value" />
        </perch:if>         
    </perch:categories>     
</perch:repeater>

Thanks for your help !