help with my first sling app

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

help with my first sling app

Eugen Stan-2
Hello,

(Dear lazy sling community)

I'm working to implement my first sling application / pages. We have to
deploy a *Terms of use* page that need to be translated across multiple
languages.

I figured this should be easy with Sling - and it's not quite as I
expected :( .

The solution that I have settled for in my head is using thymeleaf
templates and sling i18n with json files. However I need some help
implementing it.

I'm sharing what is in my head, please help correct if I am wrong. I
have been at this (and other sling related stuff - content loading, etc)
for the past few days.

My page is going to live in */content**/terms-of-us**e.ht**ml*. It's a
*nt:file*, *sling:res**ource* with *sling:resourceType = **ieugen**/page* .

Now, let's put translations for the page under 
*/lib/trans**lations/content/t**erms**-of-use**.htlm/{english**.**json*,
*deuts**ch.json}* . These files should follow the format described in [1].

My goal is for the content of the "/content/terms-of-use.html" node to
be a thymeleaf template itself. This template will use attributes like
th-text="#{text-id-from-translation-file}".

Now, the script "*ieu**gen/page*" should to the following:

- take the content of the JCR node

- load the proper translation file based on the requested language and
the node currently being rendered.

- render the content of the node (thymeleaf template - or any other
template language - handlebars?? ) by providing a context with the
translation files loaded

- extra: the content might be rendered inside a layout defined by
ieugen/page script - with common headers and footers.

My goal is to be able to create pages that are easy to internationalize.

So far I have a few setbacks:

1. I don't know how to render resource properties.

2. I don't know how to render a template inside a script.

So far, my script looks like this:

<!DOCTYPE html>
<html
data-th-with="*valueMap=${resource.adaptTo(@org.apache.sling.api.resource.ValueMap@class)}*">
<head>
  <!-- Common head -->
</head>
<body>
<div class="container">
  <span data-th-text="${resource}">This works prints the resource </span>
  <span data-th-text="${valueMap.attribute['jcr:title']}">*This fails -
valueMap is null* </span>
  <div>
     <p>*How do I render node content here**?**Node content is a
thymeleaf? template* </p>
  </div>
</div>
<footer>Common footer</footer>
</body>
</html>

Thanks,

[1]
https://sling.apache.org/documentation/bundles/internationalization-support-i18n.html#json-file-based



signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: help with my first sling app

Eugen Stan-2
Score 1 for me 99 for Sling.

I found out how to use resources in sling templates with thymeleaf.

My *ieugen/page* page  looks like this and it works. Now let's see if I
can manage to render the content using the thymeleaf rendering service
or another way.

Note to who is reading: Is there a simpler/better way to solve this?

<html data-th-with="valueMap=${resource.getValueMap()}">
<head>
</head>
<body>
<div class="container">
  <div class="panel panel-primary">
    <span data-th-text="${valueMap.get('jcr:title')}">SIMPLE PAGE</span>
  </div>
</div>
</body>
</html>

On 28.05.2018 03:35, Ioan Eugen Stan wrote:

> Hello,
>
> (Dear lazy sling community)
>
> I'm working to implement my first sling application / pages. We have to
> deploy a *Terms of use* page that need to be translated across multiple
> languages.
>
> I figured this should be easy with Sling - and it's not quite as I
> expected :( .
>
> The solution that I have settled for in my head is using thymeleaf
> templates and sling i18n with json files. However I need some help
> implementing it.
>
> I'm sharing what is in my head, please help correct if I am wrong. I
> have been at this (and other sling related stuff - content loading, etc)
> for the past few days.
>
> My page is going to live in */content**/terms-of-us**e.ht**ml*. It's a
> *nt:file*, *sling:res**ource* with *sling:resourceType = **ieugen**/page* .
>
> Now, let's put translations for the page under 
> */lib/trans**lations/content/t**erms**-of-use**.htlm/{english**.**json*,
> *deuts**ch.json}* . These files should follow the format described in [1].
>
> My goal is for the content of the "/content/terms-of-use.html" node to
> be a thymeleaf template itself. This template will use attributes like
> th-text="#{text-id-from-translation-file}".
>
> Now, the script "*ieu**gen/page*" should to the following:
>
> - take the content of the JCR node
>
> - load the proper translation file based on the requested language and
> the node currently being rendered.
>
> - render the content of the node (thymeleaf template - or any other
> template language - handlebars?? ) by providing a context with the
> translation files loaded
>
> - extra: the content might be rendered inside a layout defined by
> ieugen/page script - with common headers and footers.
>
> My goal is to be able to create pages that are easy to internationalize.
>
> So far I have a few setbacks:
>
> 1. I don't know how to render resource properties.
>
> 2. I don't know how to render a template inside a script.
>
> So far, my script looks like this:
>
> <!DOCTYPE html>
> <html
> data-th-with="*valueMap=${resource.adaptTo(@org.apache.sling.api.resource.ValueMap@class)}*">
> <head>
>   <!-- Common head -->
> </head>
> <body>
> <div class="container">
>   <span data-th-text="${resource}">This works prints the resource </span>
>   <span data-th-text="${valueMap.attribute['jcr:title']}">*This fails -
> valueMap is null* </span>
>   <div>
>      <p>*How do I render node content here**?**Node content is a
> thymeleaf? template* </p>
>   </div>
> </div>
> <footer>Common footer</footer>
> </body>
> </html>
>
> Thanks,
>
> [1]
> https://sling.apache.org/documentation/bundles/internationalization-support-i18n.html#json-file-based
>
>


signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: help with my first sling app

Oliver Lietz
On Monday 28 May 2018 11:50:25 Ioan Eugen Stan wrote:

> Score 1 for me 99 for Sling.
>
> I found out how to use resources in sling templates with thymeleaf.
>
> My *ieugen/page* page  looks like this and it works. Now let's see if I
> can manage to render the content using the thymeleaf rendering service
> or another way.
>
> Note to who is reading: Is there a simpler/better way to solve this?
>
> <html data-th-with="valueMap=${resource.getValueMap()}">
> <head>
> </head>
> <body>
> <div class="container">
>   <div class="panel panel-primary">
>     <span data-th-text="${valueMap.get('jcr:title')}">SIMPLE PAGE</span>
>   </div>
> </div>
> </body>
> </html>

There is a sample for Thymeleaf with Sling Models:

https://github.com/apache/sling-samples/tree/master/fling

Are you aware of it? Tip: Use Sling Models.

Regards,
O.

> On 28.05.2018 03:35, Ioan Eugen Stan wrote:
> > Hello,
> >
> > (Dear lazy sling community)
> >
> > I'm working to implement my first sling application / pages. We have to
> > deploy a *Terms of use* page that need to be translated across multiple
> > languages.
> >
> > I figured this should be easy with Sling - and it's not quite as I
> > expected :( .
> >
> > The solution that I have settled for in my head is using thymeleaf
> > templates and sling i18n with json files. However I need some help
> > implementing it.
> >
> > I'm sharing what is in my head, please help correct if I am wrong. I
> > have been at this (and other sling related stuff - content loading, etc)
> > for the past few days.
> >
> > My page is going to live in */content**/terms-of-us**e.ht**ml*. It's a
> > *nt:file*, *sling:res**ource* with *sling:resourceType = **ieugen**/page*
> > .
> >
> > Now, let's put translations for the page under
> > */lib/trans**lations/content/t**erms**-of-use**.htlm/{english**.**json*,
> > *deuts**ch.json}* . These files should follow the format described in [1].
> >
> > My goal is for the content of the "/content/terms-of-use.html" node to
> > be a thymeleaf template itself. This template will use attributes like
> > th-text="#{text-id-from-translation-file}".
> >
> > Now, the script "*ieu**gen/page*" should to the following:
> >
> > - take the content of the JCR node
> >
> > - load the proper translation file based on the requested language and
> > the node currently being rendered.
> >
> > - render the content of the node (thymeleaf template - or any other
> > template language - handlebars?? ) by providing a context with the
> > translation files loaded
> >
> > - extra: the content might be rendered inside a layout defined by
> > ieugen/page script - with common headers and footers.
> >
> > My goal is to be able to create pages that are easy to internationalize.
> >
> > So far I have a few setbacks:
> >
> > 1. I don't know how to render resource properties.
> >
> > 2. I don't know how to render a template inside a script.
> >
> > So far, my script looks like this:
> >
> > <!DOCTYPE html>
> > <html
> > data-th-with="*valueMap=${resource.adaptTo(@org.apache.sling.api.resource.
> > ValueMap@class)}*"> <head>
> >   <!-- Common head -->
> > </head>
> > <body>
> > <div class="container">
> >   <span data-th-text="${resource}">This works prints the resource </span>
> >   <span data-th-text="${valueMap.attribute['jcr:title']}">*This fails -
> > valueMap is null* </span>
> >   <div>
> >      <p>*How do I render node content here**?**Node content is a
> > thymeleaf? template* </p>
> >   </div>
> > </div>
> > <footer>Common footer</footer>
> > </body>
> > </html>
> >
> > Thanks,
> >
> > [1]
> > https://sling.apache.org/documentation/bundles/internationalization-suppor
> > t-i18n.html#json-file-based

Reply | Threaded
Open this post in threaded view
|

Re: help with my first sling app

Daniel Klco-2
Another thing to keep in mind is caching. If you want to make your
application scale, you will need to be able to cache the content rather
than building every response dynamically. You can either use sling
selectors to load the correct i18n dictionary or create a language root and
create one page per translation of the content.

I'd recommend the language root option as it's easier to manage the content
than updating an i18n dictionary and you can cache each page separately
using Dispatcher or mod_cache.

-Dan


On Mon, May 28, 2018, 11:13 AM Oliver Lietz <[hidden email]> wrote:

> On Monday 28 May 2018 11:50:25 Ioan Eugen Stan wrote:
> > Score 1 for me 99 for Sling.
> >
> > I found out how to use resources in sling templates with thymeleaf.
> >
> > My *ieugen/page* page  looks like this and it works. Now let's see if I
> > can manage to render the content using the thymeleaf rendering service
> > or another way.
> >
> > Note to who is reading: Is there a simpler/better way to solve this?
> >
> > <html data-th-with="valueMap=${resource.getValueMap()}">
> > <head>
> > </head>
> > <body>
> > <div class="container">
> >   <div class="panel panel-primary">
> >     <span data-th-text="${valueMap.get('jcr:title')}">SIMPLE PAGE</span>
> >   </div>
> > </div>
> > </body>
> > </html>
>
> There is a sample for Thymeleaf with Sling Models:
>
> https://github.com/apache/sling-samples/tree/master/fling
>
> Are you aware of it? Tip: Use Sling Models.
>
> Regards,
> O.
>
> > On 28.05.2018 03:35, Ioan Eugen Stan wrote:
> > > Hello,
> > >
> > > (Dear lazy sling community)
> > >
> > > I'm working to implement my first sling application / pages. We have to
> > > deploy a *Terms of use* page that need to be translated across multiple
> > > languages.
> > >
> > > I figured this should be easy with Sling - and it's not quite as I
> > > expected :( .
> > >
> > > The solution that I have settled for in my head is using thymeleaf
> > > templates and sling i18n with json files. However I need some help
> > > implementing it.
> > >
> > > I'm sharing what is in my head, please help correct if I am wrong. I
> > > have been at this (and other sling related stuff - content loading,
> etc)
> > > for the past few days.
> > >
> > > My page is going to live in */content**/terms-of-us**e.ht**ml*. It's a
> > > *nt:file*, *sling:res**ource* with *sling:resourceType =
> **ieugen**/page*
> > > .
> > >
> > > Now, let's put translations for the page under
> > >
> */lib/trans**lations/content/t**erms**-of-use**.htlm/{english**.**json*,
> > > *deuts**ch.json}* . These files should follow the format described in
> [1].
> > >
> > > My goal is for the content of the "/content/terms-of-use.html" node to
> > > be a thymeleaf template itself. This template will use attributes like
> > > th-text="#{text-id-from-translation-file}".
> > >
> > > Now, the script "*ieu**gen/page*" should to the following:
> > >
> > > - take the content of the JCR node
> > >
> > > - load the proper translation file based on the requested language and
> > > the node currently being rendered.
> > >
> > > - render the content of the node (thymeleaf template - or any other
> > > template language - handlebars?? ) by providing a context with the
> > > translation files loaded
> > >
> > > - extra: the content might be rendered inside a layout defined by
> > > ieugen/page script - with common headers and footers.
> > >
> > > My goal is to be able to create pages that are easy to
> internationalize.
> > >
> > > So far I have a few setbacks:
> > >
> > > 1. I don't know how to render resource properties.
> > >
> > > 2. I don't know how to render a template inside a script.
> > >
> > > So far, my script looks like this:
> > >
> > > <!DOCTYPE html>
> > > <html
> > >
> data-th-with="*valueMap=${resource.adaptTo(@org.apache.sling.api.resource.
> > > ValueMap@class)}*"> <head>
> > >   <!-- Common head -->
> > > </head>
> > > <body>
> > > <div class="container">
> > >   <span data-th-text="${resource}">This works prints the resource
> </span>
> > >   <span data-th-text="${valueMap.attribute['jcr:title']}">*This fails -
> > > valueMap is null* </span>
> > >   <div>
> > >      <p>*How do I render node content here**?**Node content is a
> > > thymeleaf? template* </p>
> > >   </div>
> > > </div>
> > > <footer>Common footer</footer>
> > > </body>
> > > </html>
> > >
> > > Thanks,
> > >
> > > [1]
> > >
> https://sling.apache.org/documentation/bundles/internationalization-suppor
> > > t-i18n.html#json-file-based
>
>
Reply | Threaded
Open this post in threaded view
|

Re: help with my first sling app

Eugen Stan-2
In reply to this post by Oliver Lietz
Hello Oliver,

I saw your presentation(s) on thymeleaf and Sing and I was hoping for
some feedback from you :).

I saw the sample and I am aware of Sling Models but I try to keep it as
simple as possible. I am already deep enough with new tech.

Regarding thymeleaf and sling do you know where I can find examples on
how to use OGNL in templates? All my tries failed so far. 

After going through the documentation over and over again I think that I
may have to write some servlets to make what I want.

I was hoping (and still do) to get away easy and just do:

----
|rednerer = sling.getService(ThymeleafRenderer )|

|body = renderer.render(content, context)
|

|send the response by wrapping body into layout. ||
|

|----||
|

|I will have to rethink my strategy in terms of an osgi service / custom
resource maybe and use sling.include()? Still struggling to navigate all
of what Sling has to offer. I think this should help
||https://cwiki.apache.org/confluence/display/SLING/Scripting+variables .


|||||
On 28.05.2018 18:12, Oliver Lietz wrote:

> On Monday 28 May 2018 11:50:25 Ioan Eugen Stan wrote:
>> Score 1 for me 99 for Sling.
>>
>> I found out how to use resources in sling templates with thymeleaf.
>>
>> My *ieugen/page* page  looks like this and it works. Now let's see if I
>> can manage to render the content using the thymeleaf rendering service
>> or another way.
>>
>> Note to who is reading: Is there a simpler/better way to solve this?
>>
>> <html data-th-with="valueMap=${resource.getValueMap()}">
>> <head>
>> </head>
>> <body>
>> <div class="container">
>>   <div class="panel panel-primary">
>>     <span data-th-text="${valueMap.get('jcr:title')}">SIMPLE PAGE</span>
>>   </div>
>> </div>
>> </body>
>> </html>
> There is a sample for Thymeleaf with Sling Models:
>
> https://github.com/apache/sling-samples/tree/master/fling
>
> Are you aware of it? Tip: Use Sling Models.
>
> Regards,
> O.
>
>> On 28.05.2018 03:35, Ioan Eugen Stan wrote:
>>> Hello,
>>>
>>> (Dear lazy sling community)
>>>
>>> I'm working to implement my first sling application / pages. We have to
>>> deploy a *Terms of use* page that need to be translated across multiple
>>> languages.
>>>
>>> I figured this should be easy with Sling - and it's not quite as I
>>> expected :( .
>>>
>>> The solution that I have settled for in my head is using thymeleaf
>>> templates and sling i18n with json files. However I need some help
>>> implementing it.
>>>
>>> I'm sharing what is in my head, please help correct if I am wrong. I
>>> have been at this (and other sling related stuff - content loading, etc)
>>> for the past few days.
>>>
>>> My page is going to live in */content**/terms-of-us**e.ht**ml*. It's a
>>> *nt:file*, *sling:res**ource* with *sling:resourceType = **ieugen**/page*
>>> .
>>>
>>> Now, let's put translations for the page under
>>> */lib/trans**lations/content/t**erms**-of-use**.htlm/{english**.**json*,
>>> *deuts**ch.json}* . These files should follow the format described in [1].
>>>
>>> My goal is for the content of the "/content/terms-of-use.html" node to
>>> be a thymeleaf template itself. This template will use attributes like
>>> th-text="#{text-id-from-translation-file}".
>>>
>>> Now, the script "*ieu**gen/page*" should to the following:
>>>
>>> - take the content of the JCR node
>>>
>>> - load the proper translation file based on the requested language and
>>> the node currently being rendered.
>>>
>>> - render the content of the node (thymeleaf template - or any other
>>> template language - handlebars?? ) by providing a context with the
>>> translation files loaded
>>>
>>> - extra: the content might be rendered inside a layout defined by
>>> ieugen/page script - with common headers and footers.
>>>
>>> My goal is to be able to create pages that are easy to internationalize.
>>>
>>> So far I have a few setbacks:
>>>
>>> 1. I don't know how to render resource properties.
>>>
>>> 2. I don't know how to render a template inside a script.
>>>
>>> So far, my script looks like this:
>>>
>>> <!DOCTYPE html>
>>> <html
>>> data-th-with="*valueMap=${resource.adaptTo(@org.apache.sling.api.resource.
>>> ValueMap@class)}*"> <head>
>>>   <!-- Common head -->
>>> </head>
>>> <body>
>>> <div class="container">
>>>   <span data-th-text="${resource}">This works prints the resource </span>
>>>   <span data-th-text="${valueMap.attribute['jcr:title']}">*This fails -
>>> valueMap is null* </span>
>>>   <div>
>>>      <p>*How do I render node content here**?**Node content is a
>>> thymeleaf? template* </p>
>>>   </div>
>>> </div>
>>> <footer>Common footer</footer>
>>> </body>
>>> </html>
>>>
>>> Thanks,
>>>
>>> [1]
>>> https://sling.apache.org/documentation/bundles/internationalization-suppor
>>> t-i18n.html#json-file-based


signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: help with my first sling app

Eugen Stan-2
In reply to this post by Daniel Klco-2
Hi Daniel,

On 28.05.2018 19:42, Daniel Klco wrote:
> Another thing to keep in mind is caching. If you want to make your
> application scale, you will need to be able to cache the content rather
> than building every response dynamically. You can either use sling
> selectors to load the correct i18n dictionary or create a language root and
> create one page per translation of the content.
Thanks for the suggestion. Caching is not on my radar right now but it
will. My plan is to keep all the translations for a page / piece of
content into a single json file ( second option in sing i18n page) .
Those pages will not see a lot of hits initially so I'm focusing on
making it work and then making it work fast :). I don't fully understand
the selectors use in this case. I put that on me being a noob in Sling :).
>
> I'd recommend the language root option as it's easier to manage the content
> than updating an i18n dictionary and you can cache each page separately
> using Dispatcher or mod_cache.
I think I understand but not sure since I don't know what do you mean by
a language root or Dispatcher? I'm sure it's an issue with aligning our
vocabulary.

I'll focus on rendering the page first. I will give it a try with Sling
Models as Oliver suggested. When I have that I may know more about when
I will have to look into caching. For sure I will open the discussion
again and ask for your input :).

/Eugen

> -Dan
>
>
> On Mon, May 28, 2018, 11:13 AM Oliver Lietz <[hidden email]> wrote:
>
>> On Monday 28 May 2018 11:50:25 Ioan Eugen Stan wrote:
>>> Score 1 for me 99 for Sling.
>>>
>>> I found out how to use resources in sling templates with thymeleaf.
>>>
>>> My *ieugen/page* page  looks like this and it works. Now let's see if I
>>> can manage to render the content using the thymeleaf rendering service
>>> or another way.
>>>
>>> Note to who is reading: Is there a simpler/better way to solve this?
>>>
>>> <html data-th-with="valueMap=${resource.getValueMap()}">
>>> <head>
>>> </head>
>>> <body>
>>> <div class="container">
>>>   <div class="panel panel-primary">
>>>     <span data-th-text="${valueMap.get('jcr:title')}">SIMPLE PAGE</span>
>>>   </div>
>>> </div>
>>> </body>
>>> </html>
>> There is a sample for Thymeleaf with Sling Models:
>>
>> https://github.com/apache/sling-samples/tree/master/fling
>>
>> Are you aware of it? Tip: Use Sling Models.
>>
>> Regards,
>> O.
>>
>>> On 28.05.2018 03:35, Ioan Eugen Stan wrote:
>>>> Hello,
>>>>
>>>> (Dear lazy sling community)
>>>>
>>>> I'm working to implement my first sling application / pages. We have to
>>>> deploy a *Terms of use* page that need to be translated across multiple
>>>> languages.
>>>>
>>>> I figured this should be easy with Sling - and it's not quite as I
>>>> expected :( .
>>>>
>>>> The solution that I have settled for in my head is using thymeleaf
>>>> templates and sling i18n with json files. However I need some help
>>>> implementing it.
>>>>
>>>> I'm sharing what is in my head, please help correct if I am wrong. I
>>>> have been at this (and other sling related stuff - content loading,
>> etc)
>>>> for the past few days.
>>>>
>>>> My page is going to live in */content**/terms-of-us**e.ht**ml*. It's a
>>>> *nt:file*, *sling:res**ource* with *sling:resourceType =
>> **ieugen**/page*
>>>> .
>>>>
>>>> Now, let's put translations for the page under
>>>>
>> */lib/trans**lations/content/t**erms**-of-use**.htlm/{english**.**json*,
>>>> *deuts**ch.json}* . These files should follow the format described in
>> [1].
>>>> My goal is for the content of the "/content/terms-of-use.html" node to
>>>> be a thymeleaf template itself. This template will use attributes like
>>>> th-text="#{text-id-from-translation-file}".
>>>>
>>>> Now, the script "*ieu**gen/page*" should to the following:
>>>>
>>>> - take the content of the JCR node
>>>>
>>>> - load the proper translation file based on the requested language and
>>>> the node currently being rendered.
>>>>
>>>> - render the content of the node (thymeleaf template - or any other
>>>> template language - handlebars?? ) by providing a context with the
>>>> translation files loaded
>>>>
>>>> - extra: the content might be rendered inside a layout defined by
>>>> ieugen/page script - with common headers and footers.
>>>>
>>>> My goal is to be able to create pages that are easy to
>> internationalize.
>>>> So far I have a few setbacks:
>>>>
>>>> 1. I don't know how to render resource properties.
>>>>
>>>> 2. I don't know how to render a template inside a script.
>>>>
>>>> So far, my script looks like this:
>>>>
>>>> <!DOCTYPE html>
>>>> <html
>>>>
>> data-th-with="*valueMap=${resource.adaptTo(@org.apache.sling.api.resource.
>>>> ValueMap@class)}*"> <head>
>>>>   <!-- Common head -->
>>>> </head>
>>>> <body>
>>>> <div class="container">
>>>>   <span data-th-text="${resource}">This works prints the resource
>> </span>
>>>>   <span data-th-text="${valueMap.attribute['jcr:title']}">*This fails -
>>>> valueMap is null* </span>
>>>>   <div>
>>>>      <p>*How do I render node content here**?**Node content is a
>>>> thymeleaf? template* </p>
>>>>   </div>
>>>> </div>
>>>> <footer>Common footer</footer>
>>>> </body>
>>>> </html>
>>>>
>>>> Thanks,
>>>>
>>>> [1]
>>>>
>> https://sling.apache.org/documentation/bundles/internationalization-suppor
>>>> t-i18n.html#json-file-based
>>


signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: help with my first sling app

Oliver Lietz
In reply to this post by Eugen Stan-2
On Monday 28 May 2018 23:07:57 Ioan Eugen Stan wrote:
> Hello Oliver,

Hi,

> I saw your presentation(s) on thymeleaf and Sing and I was hoping for
> some feedback from you :).
>
> I saw the sample and I am aware of Sling Models but I try to keep it as
> simple as possible. I am already deep enough with new tech.
>
> Regarding thymeleaf and sling do you know where I can find examples on
> how to use OGNL in templates? All my tries failed so far.
>
> After going through the documentation over and over again I think that I
> may have to write some servlets to make what I want.

a servlet for OGNL? No. You already showed some expressions in your code... so
what is not working? Basic OGNL is used in Fling sample and in Scripting
Thymeleaf's ITs. More advanced examples should be in Thymeleaf's
documentation.

>
> I was hoping (and still do) to get away easy and just do:
>
> ----
>
> |rednerer = sling.getService(ThymeleafRenderer )|
> |
> |body = renderer.render(content, context)
> |
> |
> |send the response by wrapping body into layout. ||
> |
> |
> |----||
> |
> |
> |I will have to rethink my strategy in terms of an osgi service / custom
>
> resource maybe and use sling.include()? Still struggling to navigate all
> of what Sling has to offer. I think this should help
>
> ||https://cwiki.apache.org/confluence/display/SLING/Scripting+variables .

Look again into the Fling sample: There is content from JCR rendered by a
Thymeleaf script (page.content), i18n used for UI elements (main use case) and
a servlet which renders a Thymeleaf template (not using Sling Scripting).

I'm usually not using i18n in projects for content but for UI elements and
messages only. The structure in JCR looks always similar:

/content/sites/project/country/language/...

HTH,
O.


> On 28.05.2018 18:12, Oliver Lietz wrote:
> > On Monday 28 May 2018 11:50:25 Ioan Eugen Stan wrote:
> >> Score 1 for me 99 for Sling.
> >>
> >> I found out how to use resources in sling templates with thymeleaf.
> >>
> >> My *ieugen/page* page  looks like this and it works. Now let's see if I
> >> can manage to render the content using the thymeleaf rendering service
> >> or another way.
> >>
> >> Note to who is reading: Is there a simpler/better way to solve this?
> >>
> >> <html data-th-with="valueMap=${resource.getValueMap()}">
> >> <head>
> >> </head>
> >> <body>
> >> <div class="container">
> >>
> >>   <div class="panel panel-primary">
> >>  
> >>     <span data-th-text="${valueMap.get('jcr:title')}">SIMPLE PAGE</span>
> >>  
> >>   </div>
> >>
> >> </div>
> >> </body>
> >> </html>
> >
> > There is a sample for Thymeleaf with Sling Models:
> >
> > https://github.com/apache/sling-samples/tree/master/fling
> >
> > Are you aware of it? Tip: Use Sling Models.
> >
> > Regards,
> > O.
> >
> >> On 28.05.2018 03:35, Ioan Eugen Stan wrote:
> >>> Hello,
> >>>
> >>> (Dear lazy sling community)
> >>>
> >>> I'm working to implement my first sling application / pages. We have to
> >>> deploy a *Terms of use* page that need to be translated across multiple
> >>> languages.
> >>>
> >>> I figured this should be easy with Sling - and it's not quite as I
> >>> expected :( .
> >>>
> >>> The solution that I have settled for in my head is using thymeleaf
> >>> templates and sling i18n with json files. However I need some help
> >>> implementing it.
> >>>
> >>> I'm sharing what is in my head, please help correct if I am wrong. I
> >>> have been at this (and other sling related stuff - content loading, etc)
> >>> for the past few days.
> >>>
> >>> My page is going to live in */content**/terms-of-us**e.ht**ml*. It's a
> >>> *nt:file*, *sling:res**ource* with *sling:resourceType =
> >>> **ieugen**/page*
> >>> .
> >>>
> >>> Now, let's put translations for the page under
> >>> */lib/trans**lations/content/t**erms**-of-use**.htlm/{english**.**json*,
> >>> *deuts**ch.json}* . These files should follow the format described in
> >>> [1].
> >>>
> >>> My goal is for the content of the "/content/terms-of-use.html" node to
> >>> be a thymeleaf template itself. This template will use attributes like
> >>> th-text="#{text-id-from-translation-file}".
> >>>
> >>> Now, the script "*ieu**gen/page*" should to the following:
> >>>
> >>> - take the content of the JCR node
> >>>
> >>> - load the proper translation file based on the requested language and
> >>> the node currently being rendered.
> >>>
> >>> - render the content of the node (thymeleaf template - or any other
> >>> template language - handlebars?? ) by providing a context with the
> >>> translation files loaded
> >>>
> >>> - extra: the content might be rendered inside a layout defined by
> >>> ieugen/page script - with common headers and footers.
> >>>
> >>> My goal is to be able to create pages that are easy to internationalize.
> >>>
> >>> So far I have a few setbacks:
> >>>
> >>> 1. I don't know how to render resource properties.
> >>>
> >>> 2. I don't know how to render a template inside a script.
> >>>
> >>> So far, my script looks like this:
> >>>
> >>> <!DOCTYPE html>
> >>> <html
> >>> data-th-with="*valueMap=${resource.adaptTo(@org.apache.sling.api.resourc
> >>> e.
> >>> ValueMap@class)}*"> <head>
> >>>
> >>>   <!-- Common head -->
> >>>
> >>> </head>
> >>> <body>
> >>> <div class="container">
> >>>
> >>>   <span data-th-text="${resource}">This works prints the resource
> >>>   </span>
> >>>   <span data-th-text="${valueMap.attribute['jcr:title']}">*This fails -
> >>>
> >>> valueMap is null* </span>
> >>>
> >>>   <div>
> >>>  
> >>>      <p>*How do I render node content here**?**Node content is a
> >>>
> >>> thymeleaf? template* </p>
> >>>
> >>>   </div>
> >>>
> >>> </div>
> >>> <footer>Common footer</footer>
> >>> </body>
> >>> </html>
> >>>
> >>> Thanks,
> >>>
> >>> [1]
> >>> https://sling.apache.org/documentation/bundles/internationalization-supp
> >>> or
> >>> t-i18n.html#json-file-based