Forum

Thread tagged as: Runway

Runway: perch:if Limit

I'm creating a multi-lingual Runway site which makes heavy use of perch:if. Here is an example of a simple text block template:

<perch:help>
    <strong>Language:</strong> <select id="languageToggle"><option value="en">English</option><option value="zh">Chinese</option><option value="fr">French</option><option value="es">Spanish</option><option value="pt">Portuguese</option></select>
</perch:help>

<!--* ENGLISH *-->
<perch:if id="lang" value="en">
    <perch:content id="en_content" type="textarea" label="Content (English)" html="true" editor="ckeditor" divider-before="Language: English" divider-after="EndLang" />
</perch:if>
<!--* CHINESE *-->
<perch:if id="lang" value="zh">
    <perch:if exists="zh_content"><perch:content id="zh_content" type="textarea" label="Content (Chinese)" html="true" editor="ckeditor" divider-before="Language: Chinese" divider-after="EndLang" /><perch:else /><perch:content id="en_content" type="textarea" label="Content (English)" html="true" editor="ckeditor" divider-before="Language: English" divider-after="EndLang" /></perch:if>
</perch:if>
<!--* FRENCH *-->
<perch:if id="lang" value="fr">
    <perch:if exists="fr_content"><perch:content id="fr_content" type="textarea" label="Content (French)" html="true" editor="ckeditor" divider-before="Language: French" divider-after="EndLang" /><perch:else /><perch:content id="en_content" type="textarea" label="Content (English)" html="true" editor="ckeditor" divider-before="Language: English" divider-after="EndLang" /></perch:if>
</perch:if>
<!--* SPANISH *-->
<perch:if id="lang" value="es">
    <perch:if exists="es_content"><perch:content id="es_content" type="textarea" label="Content (Spanish)" html="true" editor="ckeditor" divider-before="Language: Spanish" divider-after="EndLang" /><perch:else /><perch:content id="en_content" type="textarea" label="Content (English)" html="true" editor="ckeditor" divider-before="Language: English" divider-after="EndLang" /></perch:if>
</perch:if>
<!--* PORTUGUESE *-->
<perch:if id="lang" value="pt">
    <perch:if exists="pt_content"><perch:content id="pt_content" type="textarea" label="Content (Portuguese)" html="true" editor="ckeditor" divider-before="Language: Portuguese" divider-after="EndLang" /><perch:else /><perch:content id="en_content" type="textarea" label="Content (English)" html="true" editor="ckeditor" divider-before="Language: English" divider-after="EndLang" /></perch:if>
</perch:if>

I have some collections which require many fields like this, and I'm hitting the perch:if limit as described in this thread.

In that thread, Drew mentions that this limit will be raised to 1000 in 2.9. I am in a pickle here, as I need that limit raised right now. Is there any feasible workaround right now? Is the limit a simple check in a core file somewhere, or would this be a major change to the core? I don't want to edit core files, but this is mission critical and I don't appear to have a choice. Any help would be much appreciated!

EDIT: In case you'd like to see an example of a full collection template:

<perch:help>
    <strong>Language:</strong> <select id="languageToggle"><option value="en">English</option><option value="zh">Chinese</option><option value="fr">French</option><option value="es">Spanish</option><option value="pt">Portuguese</option></select>
</perch:help>

<!--* ENGLISH *-->
<perch:if id="lang" value="en">
    <perch:content title="true" required="true" id="en_title" type="text" label="Title (English)" divider-before="Language: English" /><perch:content id="slug" type="slug" for="en_title" label="Slug" editable="true" help="Used for product URL. Leave blank to generate automatically." />
    <perch:content id="en_overview" type="textarea" label="Overview (English)" html="true" editor="ckeditor" divider-after="EndLang" />
</perch:if>
<!--* CHINESE *-->
<perch:if id="lang" value="zh">
    <perch:if exists="zh_title"><perch:content id="zh_title" type="text" label="Title (Chinese)" divider-before="Language: Chinese" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
    <perch:if exists="zh_overview"><perch:content id="zh_overview" type="textarea" label="Overview (Chinese)" html="true" editor="ckeditor" divider-after="EndLang" /><perch:else /><perch:content id="en_overview" type="textarea" label="Overview (English)" html="true" editor="ckeditor" /></perch:if>
</perch:if>
<!--* FRENCH *-->
<perch:if id="lang" value="fr">
    <perch:if exists="fr_title"><perch:content id="fr_title" type="text" label="Title (French)" divider-before="Language: French" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
    <perch:if exists="fr_overview"><perch:content id="fr_overview" type="textarea" label="Overview (French)" html="true" editor="ckeditor" divider-after="EndLang" /><perch:else /><perch:content id="en_overview" type="textarea" label="Overview (English)" html="true" editor="ckeditor" /></perch:if>
</perch:if>
<!--* SPANISH *-->
<perch:if id="lang" value="es">
    <perch:if exists="es_title"><perch:content id="es_title" type="text" label="Title (Spanish)" divider-before="Language: Spanish" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
    <perch:if exists="es_overview"><perch:content id="es_overview" type="textarea" label="Overview (Spanish)" html="true" editor="ckeditor" divider-after="EndLang" /><perch:else /><perch:content id="en_overview" type="textarea" label="Overview (English)" html="true" editor="ckeditor" /></perch:if>
</perch:if>
<!--* PORTUGUESE *-->
<perch:if id="lang" value="pt">
    <perch:if exists="pt_title"><perch:content id="pt_title" type="text" label="Title (Portuguese)" divider-before="Language: Portuguese" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
    <perch:if exists="pt_overview"><perch:content id="pt_overview" type="textarea" label="Overview (Portuguese)" html="true" editor="ckeditor" divider-after="EndLang" /><perch:else /><perch:content id="en_overview" type="textarea" label="Overview (English)" html="true" editor="ckeditor" /></perch:if>
</perch:if>

<perch:content type="image" id="image" label="Image" width="800" divider-after="Type-Specific Specs" bucket="Products" />


<!--* ENGLISH *-->
<perch:if id="lang" value="en">
    <perch:content id="en_type_capacity" type="text" label="Capacity (English)" divider-before="Language: English" />
    <perch:content id="en_type_brakes" type="text" label="Brakes (English)" />
    <perch:content id="en_type_min_wheel_size" type="text" label="Min Wheel Size (English)" />
    <perch:content id="en_type_vehicles" type="text" label="Vehicles (English)" />
    <perch:content id="en_type_wheel_mounting" type="text" label="Wheel Mounting (English)" />
    <perch:content id="en_type_final_ratio" type="text" label="Final Ratio (English)" divider-after="EndLang" />
</perch:if>
<!--* CHINESE *-->
<perch:if id="lang" value="zh">
    <perch:if exists="zh_type_capacity"><perch:content id="zh_type_capacity" type="text" label="Capacity (Chinese)" divider-before="Language: Chinese" /><perch:else /><perch:content id="en_type_capacity" type="text" label="Capacity (English)" /></perch:if>
    <perch:if exists="zh_type_brakes"><perch:content id="zh_type_brakes" type="text" label="Brakes (Chinese)" /><perch:else /><perch:content id="en_type_brakes" type="text" label="Brakes (English)" /></perch:if>
    <perch:if exists="zh_type_min_wheel_size"><perch:content id="zh_type_min_wheel_size" type="text" label="Min Wheel Size (Chinese)" /><perch:else /><perch:content id="en_type_min_wheel_size" type="text" label="Min Wheel Size (English)" /></perch:if>
    <perch:if exists="zh_type_vehicles"><perch:content id="zh_type_vehicles" type="text" label="Vehicles (Chinese)" /><perch:else /><perch:content id="en_type_vehicles" type="text" label="Vehicles (English)" /></perch:if>
    <perch:if exists="zh_type_wheel_mounting"><perch:content id="zh_type_wheel_mounting" type="text" label="Wheel Mounting (Chinese)" /><perch:else /><perch:content id="en_type_wheel_mounting" type="text" label="Wheel Mounting (English)" /></perch:if>
    <perch:if exists="zh_type_final_ratio"><perch:content id="zh_type_final_ratio" type="text" label="Final Ratio (Chinese)" divider-after="EndLang" /><perch:else /><perch:content id="en_type_final_ratio" type="text" label="Final Ratio (English)" /></perch:if>
</perch:if>
<!--* FRENCH *-->
<perch:if id="lang" value="fr">
    <perch:if exists="fr_type_capacity"><perch:content id="fr_type_capacity" type="text" label="Capacity (French)" divider-before="Language: French" /><perch:else /><perch:content id="en_type_capacity" type="text" label="Capacity (English)" /></perch:if>
    <perch:if exists="fr_type_brakes"><perch:content id="fr_type_brakes" type="text" label="Brakes (French)" /><perch:else /><perch:content id="en_type_brakes" type="text" label="Brakes (English)" /></perch:if>
    <perch:if exists="fr_type_min_wheel_size"><perch:content id="fr_type_min_wheel_size" type="text" label="Min Wheel Size (French)" /><perch:else /><perch:content id="en_type_min_wheel_size" type="text" label="Min Wheel Size (English)" /></perch:if>
    <perch:if exists="fr_type_vehicles"><perch:content id="fr_type_vehicles" type="text" label="Vehicles (French)" /><perch:else /><perch:content id="en_type_vehicles" type="text" label="Vehicles (English)" /></perch:if>
    <perch:if exists="fr_type_wheel_mounting"><perch:content id="fr_type_wheel_mounting" type="text" label="Wheel Mounting (French)" /><perch:else /><perch:content id="en_type_wheel_mounting" type="text" label="Wheel Mounting (English)" /></perch:if>
    <perch:if exists="fr_type_final_ratio"><perch:content id="fr_type_final_ratio" type="text" label="Final Ratio (French)" divider-after="EndLang" /><perch:else /><perch:content id="en_type_final_ratio" type="text" label="Final Ratio (English)" /></perch:if>
</perch:if>
<!--* SPANISH *-->
<perch:if id="lang" value="es">
    <perch:if exists="es_type_capacity"><perch:content id="es_type_capacity" type="text" label="Capacity (Spanish)" divider-before="Language: Spanish" /><perch:else /><perch:content id="en_type_capacity" type="text" label="Capacity (English)" /></perch:if>
    <perch:if exists="es_type_brakes"><perch:content id="es_type_brakes" type="text" label="Brakes (Spanish)" /><perch:else /><perch:content id="en_type_brakes" type="text" label="Brakes (English)" /></perch:if>
    <perch:if exists="es_type_min_wheel_size"><perch:content id="es_type_min_wheel_size" type="text" label="Min Wheel Size (Spanish)" /><perch:else /><perch:content id="en_type_min_wheel_size" type="text" label="Min Wheel Size (English)" /></perch:if>
    <perch:if exists="es_type_vehicles"><perch:content id="es_type_vehicles" type="text" label="Vehicles (Spanish)" /><perch:else /><perch:content id="en_type_vehicles" type="text" label="Vehicles (English)" /></perch:if>
    <perch:if exists="es_type_wheel_mounting"><perch:content id="es_type_wheel_mounting" type="text" label="Wheel Mounting (Spanish)" /><perch:else /><perch:content id="en_type_wheel_mounting" type="text" label="Wheel Mounting (English)" /></perch:if>
    <perch:if exists="es_type_final_ratio"><perch:content id="es_type_final_ratio" type="text" label="Final Ratio (Spanish)" divider-after="EndLang" /><perch:else /><perch:content id="en_type_final_ratio" type="text" label="Final Ratio (English)" /></perch:if>
</perch:if>
<!--* PORTUGUESE *-->
<perch:if id="lang" value="pt">
    <perch:if exists="pt_type_capacity"><perch:content id="pt_type_capacity" type="text" label="Capacity (Portuguese)" divider-before="Language: Portuguese" /><perch:else /><perch:content id="en_type_capacity" type="text" label="Capacity (English)" /></perch:if>
    <perch:if exists="pt_type_brakes"><perch:content id="pt_type_brakes" type="text" label="Brakes (Portuguese)" /><perch:else /><perch:content id="en_type_brakes" type="text" label="Brakes (English)" /></perch:if>
    <perch:if exists="pt_type_min_wheel_size"><perch:content id="pt_type_min_wheel_size" type="text" label="Min Wheel Size (Portuguese)" /><perch:else /><perch:content id="en_type_min_wheel_size" type="text" label="Min Wheel Size (English)" /></perch:if>
    <perch:if exists="pt_type_vehicles"><perch:content id="pt_type_vehicles" type="text" label="Vehicles (Portuguese)" /><perch:else /><perch:content id="en_type_vehicles" type="text" label="Vehicles (English)" /></perch:if>
    <perch:if exists="pt_type_wheel_mounting"><perch:content id="pt_type_wheel_mounting" type="text" label="Wheel Mounting (Portuguese)" /><perch:else /><perch:content id="en_type_wheel_mounting" type="text" label="Wheel Mounting (English)" /></perch:if>
    <perch:if exists="pt_type_final_ratio"><perch:content id="pt_type_final_ratio" type="text" label="Final Ratio (Portuguese)" divider-after="EndLang" /><perch:else /><perch:content id="en_type_final_ratio" type="text" label="Final Ratio (English)" /></perch:if>
</perch:if>

<perch:repeater id="additional_specs" label="Additional Specs" divider-before="Additional Specs" >
    <!--* ENGLISH *-->
    <perch:if id="lang" value="en">
        <perch:content id="en_label" type="text" label="Label (English)" divider-before="Language: English" />
        <perch:content id="en_spec" type="text" label="Spec (English)" divider-after="EndLang" />
    </perch:if>
    <!--* CHINESE *-->
    <perch:if id="lang" value="zh">
        <perch:if exists="zh_label"><perch:content id="zh_label" type="text" label="Label (Chinese)" divider-before="Language: Chinese" /><perch:else /><perch:content id="en_label" type="text" label="Label (English)" /></perch:if>
        <perch:if exists="zh_spec"><perch:content id="zh_spec" type="text" label="Spec (Chinese)" divider-after="EndLang" /><perch:else /><perch:content id="en_spec" type="text" label="Spec (English)" /></perch:if>
    </perch:if>
    <!--* FRENCH *-->
    <perch:if id="lang" value="fr">
        <perch:if exists="fr_label"><perch:content id="fr_label" type="text" label="Label (French)" divider-before="Language: French" /><perch:else /><perch:content id="en_label" type="text" label="Label (English)" /></perch:if>
        <perch:if exists="fr_spec"><perch:content id="fr_spec" type="text" label="Spec (French)" divider-after="EndLang" /><perch:else /><perch:content id="en_spec" type="text" label="Spec (English)" /></perch:if>
    </perch:if>
    <!--* SPANISH *-->
    <perch:if id="lang" value="es">
        <perch:if exists="es_label"><perch:content id="es_label" type="text" label="Label (Spanish)" divider-before="Language: Spanish" /><perch:else /><perch:content id="en_label" type="text" label="Label (English)" /></perch:if>
        <perch:if exists="es_spec"><perch:content id="es_spec" type="text" label="Spec (Spanish)" divider-after="EndLang" /><perch:else /><perch:content id="en_spec" type="text" label="Spec (English)" /></perch:if>
    </perch:if>
    <!--* PORTUGUESE *-->
    <perch:if id="lang" value="pt">
        <perch:if exists="pt_label"><perch:content id="pt_label" type="text" label="Label (Portuguese)" divider-before="Language: Portuguese" /><perch:else /><perch:content id="en_label" type="text" label="Label (English)" /></perch:if>
        <perch:if exists="pt_spec"><perch:content id="pt_spec" type="text" label="Spec (Portuguese)" divider-after="EndLang" /><perch:else /><perch:content id="en_spec" type="text" label="Spec (English)" /></perch:if>
    </perch:if>
</perch:repeater>

<perch:repeater id="product_literature" label="Product Literature" divider-before="Attached Documents">
    <!--* ENGLISH *-->
    <perch:if id="lang" value="en">
        <perch:content id="en_title" type="text" label="Title (English)" divider-before="Language: English" />
        <perch:content id="en_file" type="file" bucket="Literature" label="File (English)" divider-after="EndLang" />
    </perch:if>
    <!--* CHINESE *-->
    <perch:if id="lang" value="zh">
        <perch:if exists="zh_title"><perch:content id="zh_title" type="text" label="Title (Chinese)" divider-before="Language: Chinese" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
        <perch:if exists="zh_file"><perch:content id="zh_file" type="file" bucket="Literature" label="File (Chinese)" divider-after="EndLang" /><perch:else /><perch:content id="en_file" type="file" bucket="Literature" label="File (English)" /></perch:if>
    </perch:if>
    <!--* FRENCH *-->
    <perch:if id="lang" value="fr">
        <perch:if exists="fr_title"><perch:content id="fr_title" type="text" label="Title (French)" divider-before="Language: French" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
        <perch:if exists="fr_file"><perch:content id="fr_file" type="file" bucket="Literature" label="File (French)" divider-after="EndLang" /><perch:else /><perch:content id="en_file" type="file" bucket="Literature" label="File (English)" /></perch:if>
    </perch:if>
    <!--* SPANISH *-->
    <perch:if id="lang" value="es">
        <perch:if exists="es_title"><perch:content id="es_title" type="text" label="Title (Spanish)" divider-before="Language: Spanish" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
        <perch:if exists="es_file"><perch:content id="es_file" type="file" bucket="Literature" label="File (Spanish)" divider-after="EndLang" /><perch:else /><perch:content id="en_file" type="file" bucket="Literature" label="File (English)" /></perch:if>
    </perch:if>
    <!--* PORTUGUESE *-->
    <perch:if id="lang" value="pt">
        <perch:if exists="pt_title"><perch:content id="pt_title" type="text" label="Title (Portuguese)" divider-before="Language: Portuguese" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
        <perch:if exists="pt_file"><perch:content id="pt_file" type="file" bucket="Literature" label="File (Portuguese)" divider-after="EndLang" /><perch:else /><perch:content id="en_file" type="file" bucket="Literature" label="File (English)" /></perch:if>
    </perch:if>
</perch:repeater>

<perch:repeater id="service_manuals" label="Service Manuals">
    <!--* ENGLISH *-->
    <perch:if id="lang" value="en">
        <perch:content id="en_title" type="text" label="Title (English)" divider-before="Language: English" />
        <perch:content id="en_file" type="file" bucket="Manuals" label="File (English)" divider-after="EndLang" />
    </perch:if>
    <!--* CHINESE *-->
    <perch:if id="lang" value="zh">
        <perch:if exists="zh_title"><perch:content id="zh_title" type="text" label="Title (Chinese)" divider-before="Language: Chinese" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
        <perch:if exists="zh_file"><perch:content id="zh_file" type="file" bucket="Manuals" label="File (Chinese)" divider-after="EndLang" /><perch:else /><perch:content id="en_file" type="file" bucket="Manuals" label="File (English)" /></perch:if>
    </perch:if>
    <!--* FRENCH *-->
    <perch:if id="lang" value="fr">
        <perch:if exists="fr_title"><perch:content id="fr_title" type="text" label="Title (French)" divider-before="Language: French" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
        <perch:if exists="fr_file"><perch:content id="fr_file" type="file" bucket="Manuals" label="File (French)" divider-after="EndLang" /><perch:else /><perch:content id="en_file" type="file" bucket="Manuals" label="File (English)" /></perch:if>
    </perch:if>
    <!--* SPANISH *-->
    <perch:if id="lang" value="es">
        <perch:if exists="es_title"><perch:content id="es_title" type="text" label="Title (Spanish)" divider-before="Language: Spanish" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
        <perch:if exists="es_file"><perch:content id="es_file" type="file" bucket="Manuals" label="File (Spanish)" divider-after="EndLang" /><perch:else /><perch:content id="en_file" type="file" bucket="Manuals" label="File (English)" /></perch:if>
    </perch:if>
    <!--* PORTUGUESE *-->
    <perch:if id="lang" value="pt">
        <perch:if exists="pt_title"><perch:content id="pt_title" type="text" label="Title (Portuguese)" divider-before="Language: Portuguese" /><perch:else /><perch:content id="en_title" type="text" label="Title (English)" /></perch:if>
        <perch:if exists="pt_file"><perch:content id="pt_file" type="file" bucket="Manuals" label="File (Portuguese)" divider-after="EndLang" /><perch:else /><perch:content id="en_file" type="file" bucket="Manuals" label="File (English)" /></perch:if>
    </perch:if>
</perch:repeater>

<perch:categories id="products" set="Products" label="Product Category" display-as="checkboxes" divider-before="Categories" >
    <a href="/category/<perch:category id="catPath" />"><perch:category id="catTitle" /></a>
</perch:categories>

<perch:categories id="markets" set="Markets" label="Market Category" display-as="checkboxes" >
    <a href="/category/<perch:category id="catPath" />"><perch:category id="catTitle" /></a>
</perch:categories>
Shane Lenzen

Shane Lenzen 18 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I'd say this template is doing too much. It looks as though you only display one language at a time, so instead of switching with perch:if within the template, why not break it down into smaller, simpler templates?

perch_collection('Name', [
    'template' => 'foo_'.$lang
]);

and then in foo_en.html etc you don't even need to check which language you're displaying.

Obviously you'll want to keep things together for the master template, but in that one you don't need all the conditionals, so it too can be simplified.

Great idea, thanks Drew!