Do you have some feature in mind that you'd love to see in Couch? Let us know.
7 posts Page 1 of 1
Just thinking (on the subject of the multi language site approach KK has helped me with - viewtopic.php?f=8&t=74&p=10934#p10934 ) that it may be useful to have Preload Replace functionality like this [http://ellislab.com/expressionengine/user-guide/templates/globals/preload_replacement.html

I can see benefit in a multilang site because if we could check a session / variable and feed it into a preload replace then rather than having to stack conditionals like this:

Code: Select all
<cms:if my_lang='en'><cms:show content_en /></cms:if>
<cms:if my_lang='fr'><cms:show content_fr /></cms:if>
<cms:if my_lang='es'><cms:show content_es /></cms:if>         
<cms:if my_lang='de'><cms:show content_de /></cms:if>   


which works fine for simple fields, instead we would do something like:

Code: Select all
<cms:preload_replace variable_name="replacement">
<cms:show content_"replacement" />


because been able to do something like this (or even simply place a variable in a <cms:show />) means we could "tag" on the end of every field in a page thus no need to wrap them all with conditional statements like below:


Code: Select all
<h1><cms:if my_lang='de'><cms:show tagline_de /></cms:if></h1>
<p><cms:if my_lang='de'><cms:show content_de /></cms:if></p>
<h1><cms:if my_lang='es'><cms:show tagline_de /></cms:if></h1>
<p><cms:if my_lang='es'>cms:show content_es /></cms:if></p>


ExpressionEngine allows you to assign text to be replaced prior to a template being parsed, to save time typing and editing certain bits of text that might get used multiple times. Preload Replacements act as a straight string replacement for use later in the same template.

Assignment and replacement occurs instantly when the template is loaded, before any tags are parsed, and therefore may not be affected by the result of another tag’s output.
Hi Patrick,

If using all those conditionals was worrying you - the original thread did mention an alternative (and it looks to be doing the same job as the Preload Replace functionality you mentioned).

I'll quote from viewtopic.php?p=9010#p9010
So as you can see from the code above, instead of a single <cms:show variable_name /> statement, we now have to use as many statements as there are languages - each within a conditional.
If this seems tedious, you can use the following single statement instead -

<cms:get "content_<cms:show my_lang />" />

If 'cms:get' seems unfamiliar to you, please take a look at the documentation.
It is slightly different from 'cms:show' in that it takes a string as its parameter and so we can fabricate a string dynamically as we did in our example above.
The <cms:get "content_<cms:show my_lang />" /> will evaluate to
<cms:get "content_en" /> if my_lang is 'en' and
<cms:get "content_fr" /> if it is 'fr'.
As you can see, you may have any number of languages but you'll only require to use only one 'cms:get' statement.


So the stack of conditionals you mentioned
Code: Select all
<cms:if my_lang='en'><cms:show content_en /></cms:if>
<cms:if my_lang='fr'><cms:show content_fr /></cms:if>
<cms:if my_lang='es'><cms:show content_es /></cms:if>         
<cms:if my_lang='de'><cms:show content_de /></cms:if>

can be replaced with a single statement
Code: Select all
<cms:get "content_<cms:show my_lang />" />

Does this help? Please let me know.
Thanks.
Thanks KK! Apologies I completely overlooked that part of the previous thread. I have that working great and the "get" method is very good, with that combiniation / example approach then I'd agree that preload replace may not be required as we can simple define "set" things and call them and "fabricate a string dynamically ".

Thanks again! :)
Hi KK,

Just wondering, following on from the session fun I am having, is whether we can use them to order products by price or name ascending or descending, using two dropdowns:

Sort By:
- Price
- Name

Order by:
- Asc
- Desc

then do something like this:

<cms:pages masterpage='online-store.php' folder=k_folder_name paginate='1' limit='2' orderby='<cms:get "<cms:show my_sort />" />' order='<cms:get "<cms:show my_order />" />''>


Where the "my_" are the variables set based on the session like you outlined in your post. - Just wondering if we can pass that into the <cms:pages> tag?

I've already managed to create a pretty simple "view switcher" for the product catalogue from list to grid view doing the following (rough):


the view-switcher portion of both the below:

<cms:form method="post" anchor='0'>
<cms:if k_success >
<cms:set_session name='viewmode' value='list' />
<cms:redirect k_page_link />
</cms:if>
<cms:input name="submit" type="submit" value="List" class="btn pull-right ml10" />
</cms:form>

<cms:form method="post" anchor='0'>
<cms:if k_success >
<cms:set_session name='viewmode' value='grid' />
<cms:redirect k_page_link />
</cms:if>
<cms:input name="submit" type="submit" value="Grid" class="btn pull-right ml10" />
</cms:form>



My online-store.php
<cms:if my_view='list'>
<cms:embed 'online_store_list.tpl' />
</cms:if>

<cms:if my_view='grid'>
<cms:embed 'online_store_list_grid.tpl' />
</cms:if>


The view setter include:

<cms:set my_view="<cms:get_session 'viewmode' />" />
<cms:if my_view!='list' && my_view!='grid'>
<cms:set my_view='grid' />
</cms:if>

<cms:set orderby="<cms:get_session 'viewmode' />" />
<cms:if orderby!='price' && orderby!='name'>
<cms:set orderby='name' />
</cms:if>
Hi Patrick,

Yes, we can certainly use session variables to set cms:pages parameters (the tag doesn't really care where the variable comes from so long as it contains a valid value).

So, for example, if you create a switcher to set a session variable named 'my_orderby' (similar to how you create the one for 'viewmode'), following could be a way to use the session variable we set -
Code: Select all
<!-- sanity check for acceptable values -->
<cms:set my_orderby="<cms:get_session 'my_orderby' />" />
<cms:if my_orderby!='price' && my_orderby!='name'>
    <cms:set my_orderby='name' />
</cms:if>

<!-- Use the variable as a parameter -->
<cms:pages masterpage='online-store.php' orderby=my_orderby >..</cms:pages>

We can similarly use a second session variable to supply the 'order'.

Does this answer your query? Please let me know.
Thanks.
thanks KK, you've set me on the right track now - I see my error, and understand now I can pass a variable in and I didn't need the single quotes or what I was trying.

I'll work on it over the weekend and I'll post the completed (tidy) working samples in the forums for a complete online store switcher that will allow the previous sort by plus have a show X many results selector.
I worked to do something similar at viewtopic.php?f=4&t=5504, perhaps it may be a helpful read.
7 posts Page 1 of 1
cron