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

Reply via email to