Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
9 posts Page 1 of 1
Hi! :D Again with a brilliant idea, saving tons of time. :lol:

This is great for ready-made templates. Source idea: http://docs.couchcms.com/tutorials/portfolio-site/about-us.html

I enriched it with <cms:hide> tag http://docs.couchcms.com/tags-reference/hide.html
So, let's get started!!

First, we take the source unmodified html:
Code: Select all
<p>This is our great product:<p>

Then, we enclose the editable part with as many nested editable tags, as we have languages:
Code: Select all
<cms:editable name='content_en' type='richtext' >
<cms:editable name='content_ru' type='richtext' >
<p>This is our great product:<p>
<cms:editable />
<cms:editable />

If we save now and refresh - the template in admin panel would naturally have 2 editables, which will be modified (text translated) and stored in database each under its unique name. So, as we have them in memory - let's show them according to the language choice :D . I will use the technique with lang_getter, described here many times (you can send me pm, if any trouble).
Code: Select all
<cms:get "content_<cms:show my_lang "/>

Now, we refresh and see the content outputted twice: normal code inside the editables and another instance of content output by cms:get. Let's hide the source! We have to do just one small addition to the whole code, in order to hide it. So the full code can look like this:
Code: Select all
<!DOCTYPE html><cms:embed 'lang_getter.html' /><html lang="<cms:show my_lang />">
<body>
<cms:hide>
<cms:editable name='content_en' type='richtext' >
<cms:editable name='content_ru' type='richtext' >
<p>This is our great product:<p>
<cms:editable />
<cms:editable />
</cms:hide>
<cms:get "content_<cms:show my_lang "/>
</body>
</html>

The trick is to embrace the editables with <cms:hide></cms:hide>. This tag does not ignore what's inside, unlike <cms:ignore></cms:ignore>. So, what's inside the hide tag is taken into account, but is not showed to the visitor. We, instead, show only what it is supposed to.

Pls, comment. :mrgreen:
Hi @trendoman :)

Nesting of editable regions is not a recommended practice.
I can't see anything gained by doing so except making the contents of the inner region the default contents of the outer region. So, for example, in your code
Code: Select all
<cms:editable name='content_en' type='richtext' >
<cms:editable name='content_ru' type='richtext' >
<p>This is our great product:<p>
<cms:editable />
<cms:editable />

Since the inner tags are always evaluated first, the highlighted part will execute first
<cms:editable name='content_en' type='richtext' >
<cms:editable name='content_ru' type='richtext' >
<p>This is our great product:<p>
<cms:editable />

<cms:editable />

Which would result in the following -
<cms:editable name='content_en' type='richtext' >
<p>This is our great product:<p>
<cms:editable />

And that would then become the default text of the outer region.

Now anytime text in 'content_ru' is modified, and the template is accessed by a super-admin, the new contents will become the default contents of 'content_en'

Net result is that, if 'content_en' is left empty, the contents of 'content_ru' (now the default for 'en') would be shown.

That is a very roundabout way of achieving that (if at all, that is what you were trying to achieve).

As for using <cms:hide> to suppress the output of the regions - it will work the way you stated but then the standard way of enclosing all regions by <cms:template> also does the very same thing (i.e. prevents any output).

I think you should give this solution a re-think :)
Now anytime text in 'content_ru' is modified

Upon modification, hitting Save updates content in both fields. So, no surprises can be here.

<cms:template> suppress..

We can't enclose the content with cms:template, it is not intended for that, but with cms:hide it is ok.

The point is that this solution works and achieves what is stated - make any html/css template multilanguage-ready in no time. Is there any use case, where it won't work?
the new contents will become the default contents of 'content_en'

Actually, the default content is not stored in database by editable after modification. So, after the very first save - we have 2 different variables, filled with what is saved, not default content..
And thanks to the design of couch - the content never has any couch tags, so no hacking is required at all.
I'm sure we can have 10 languages (nested) without issues. And no good idea can be a bad idea, i guess :)
You missed the part where @KK said in bold:
Now anytime text in 'content_ru' is modified, and the template is accessed by a super-admin, the new contents will become the default contents of 'content_en'

I don't think you quite comprehend the implications of nesting the editable regions; it is an unmistakable anti-pattern.

The main thread on this matter speaks for itself - viewtopic.php?f=8&t=74.
@cheesypoof, I didn't miss anything @KK said. But anyway, thanks for taking part in discussion.

U see, visiting template as super-admin doesn't change anything in actual database in our case. The next part about nesting reminds me a discussion of never using a go-to expression.

We were taught (were you?) in universities about how to structure a program code avoiding shady stuff like go-to, but did it help anyone to become a great programmer, or create the next facebook? You see, I accept your logic of avoiding nesting only from the 'heights' of 'correctness', which is always as doubtful as religious at the same time.

Let's focus on what can be achieved and what can not. And put 'scary stories' away. Especially with such emotional expressions that you selected to describe your feelings.

Don't get personal, bro. Nesting a tag costs the society less resources, than duplicating content or extra time of work. :mrgreen:
KK wrote: I can't see anything gained by doing so except making the contents of the inner region the default contents of the outer region.
I think the intent of this method is to initialize the same default content for all of the different languages at the same time. For something like a richtext product description where a lot of the data - image, price, sizes, etc. - doesn't change from one language to another - I can see some advantage. The more languages, the greater the advantage.

From what @KK says, the only thing to watch out for is that if you delete one of the outer layers and leave it empty, it will be filled by the current content of the innermost layer. Maybe that's a non-problem in this case, even if it ever comes up.

As a technique for initializing complex content on muli-language sites, this seems to work, if you're careful about unintended consequences. But it's not really all that much different from the canonical solution:
Code: Select all
<cms:editable name='content_en' type='richtext' >
<p>This is our great product:<p>
</editable>
<cms:editable name='content_ru' type='richtext' >
<p>This is our great product:<p>
</editable>

The cost to society in resources, duplicated content, and work seems pretty small here.

I don't know any university coding. I'm simply a playground coder. But I am pretty old, so I can say this. Standards, best practices, canonical methods, they come from experience. This is the way that those who've been this way before say, "Watch out. Don't bang your head on that corner." Most of us go ahead and knock our heads anyway, though.
Thanks, @tim. Same world, same corners for eternity :) Even greatest minds of our time spent precious time demystifying almost religious concepts (Knuth on go-to, Linux core on the same topic).

watch out for is that if you delete one of the outer layers and leave it empty, it will be filled by the current content of the innermost layer

What did you mean by that - removing physically the editables? If so, then corresponding field is deleted as well, you know it. So, I guess, you said about the other option. If user deletes data in ckeditor, then a variable gets it's default content, which is the same for all nested editables. Good, if this is intented. Not so good, if some text should not be shown at all as some language. However, the nature of website translations is right the opposite. If something is hidden, it is done so in native language first, so we might take this valuable info, when choosing the language of the parent nest. Thanks again. :)
I enjoy your lively and thoughtful discussion, @trendoman. :)

There is an aphorism:
"Success is sweet, but cherish your failures, for they are your teachers."
If I cherish learning from my own mistakes, then learning from the mistakes of others is a great boon and a blessing!

It's true that breaking convention and dogma is a great way to do something brilliant and transformational. But take some care! For every one breakthrough, there are countless times it leads instead to disaster and regret. The world is always changing, but there are patterns. The things that crack you in the shins keep turning up in the same places.

All the universe is an unimaginably complex texture of layered, crossing, and interwoven fluid patterns. Discerning and negotiating these patterns is the way that each of us engages with the mystery of life.

Cheers!
Tim
9 posts Page 1 of 1

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 1 guest