kirby-TranslatedLayout icon indicating copy to clipboard operation
kirby-TranslatedLayout copied to clipboard

toLayouts() question

Open Small-Systems opened this issue 2 years ago • 2 comments

I have a question about the output of content in templates using the toLayouts() function.

Here is a super simple example use case of the plugin.

Notice below how the content of the gallery block in the English translation is empty.

In the panel your plugin is looping through the layouts/columns/blocks and uses the original or the translation correctly in the layouts field.

However, when using toLayouts() the plugin has no effect on the output of the field (I get an empty gallery block). Is this expected behavior?

Original German, gallery block can not be translated, text block can be translated

Layout:[{
    "attrs":[],
    "columns":[{
        "blocks":[
            {"content":{"images":["file:\/\/pUItlwkKx2BPwkZg"]},"id":"92a42692-4713-4fb0-af51-87e34c8e9910","isHidden":false,"type":"gallery"},
            {"content":{"text":"<p>Some text DE<\/p>"},"id":"d7d234c2-04fc-4404-9dc3-f4c2236e8171","isHidden":false,"type":"text"}
        ],"id":"b861ad97-48ca-4801-9aa7-5be1dd5116c4","width":"1\/1"
    }],"id":"35edf6df-f948-4bf8-a17c-eb32a4cdc7b9"
}]

English translated layout, only text block has been translated

Layout: [{
    "attrs":[],
    "columns":[{
        "blocks":[
            {"content":[],"id":"92a42692-4713-4fb0-af51-87e34c8e9910","isHidden":false,"type":"gallery"},
            {"content":{"text":"<p>Some text EN<\/p>"},"id":"d7d234c2-04fc-4404-9dc3-f4c2236e8171","isHidden":false,"type":"text"}
        ],"id":"b861ad97-48ca-4801-9aa7-5be1dd5116c4","width":"1\/1"}
    ],"id":"35edf6df-f948-4bf8-a17c-eb32a4cdc7b9"
}]

Small-Systems avatar Mar 25 '23 13:03 Small-Systems

Hello, I haven't investigated looping/rendering the blocks a lot yet. Right now there's no sanitisation options/methods for parsing content, everything is done on storing the data, then it's simply retrieved by native functions (Cms/Field namespace). So the native toLayout method should work; if not, does your content files get written correctly ? It could be broken, I haven't used this for a while. However, on the panel side (Form/Field namespace), the panel parses content on retrieval, that's why it could work there.

Daandelange avatar Apr 01 '23 19:04 Daandelange

Hello, Sorry for the delay. You were correct, toLayouts wasn't working with translated content, only in the primary language. Now, since v1.0.3 (Kirby5) there's a toTranslatedLayouts() method which handles translation injection into the primary language object. ;)

Daandelange avatar May 01 '25 09:05 Daandelange