Fórumok

ADT Template, how to use template key?

thumbnail
Daniele Baggio, módosítva 10 év-val korábban

ADT Template, how to use template key?

Expert Bejegyzések: 336 Csatlakozás dátuma: 2008.12.05. Legújabb bejegyzések


Using ADT in my own custom portlet i want to write a freemaler template that includes another template.
I have not found any example to know how to do it, i think maybe it will be something like this:

In freemarker: <#include "11514">

But this cause an error:

Caused by: java.io.IOException: Unable to find FreeMarker template with ID 11514
at com.liferay.portal.freemarker.LiferayTemplateCache.doGetTemplate(LiferayTemplateCache.java:147)
at com.liferay.portal.freemarker.LiferayTemplateCache.getTemplate(LiferayTemplateCache.java:102)

Any idea?
thumbnail
Eduardo P. García, módosítva 3 év-val korábban

RE: ADT Template, how to use template key?

Regular Member Bejegyzések: 157 Csatlakozás dátuma: 2012.03.16. Legújabb bejegyzések
Ciao Daniele,

In order to include another template through its key, you have to prepend the templates path. This way the engine knows that the key represents an existing template. The templates path is available as a variable in the template context. Try this:

&lt;#include "${templatesPath}/11514" /&gt;


Thanks!
thumbnail
Daniele Baggio, módosítva 10 év-val korábban

RE: ADT Template, how to use template key?

Expert Bejegyzések: 336 Csatlakozás dátuma: 2008.12.05. Legújabb bejegyzések
Sorry but i continue to have the problem.

I have tried this situation:

This is the script to be included:


The value of ${templatesPath} is _TEMPLATE_CONTEXT_/10157/10184

The code where i wqnt to include the template is:

&lt;#include "${templatesPath}/16901" /&gt;


The result is:


An error occurred while processing the template.
Error reading included file _TEMPLATE_CONTEXT_/10157/10184/16901


p.s. I am using LF 6.2 beta 2
thumbnail
Eduardo P. García, módosítva 3 év-val korábban

RE: ADT Template, how to use template key?

Regular Member Bejegyzések: 157 Csatlakozás dátuma: 2012.03.16. Legújabb bejegyzések
Hi Daniele,

I'm using Beta 3 but we haven't done any changes in this feature recently. It's working fine for me following these steps:

1. Go to Web Content > Manage Structures and add a new Structure with any field
2. For the above created structure, add two FTL templates:

[indent]"Included template", with the content:

<p>This is an included template</p>


"Main template", with the content:

&lt;#include "${templatesPath}/12345" /&gt;

<p>This is my main template</p>


Assuming that 12345 is the templateKey of the "Included template".[/indent]

3. Add a Web Content using the structure created in step 1 and the Main Template.
4. Add a Web Content Display portlet to a page and select the web content created in step 3 to be displayed. The portlet displays:

This is an included template
This is my main template


Please describe which steps you're following so we can determine where the issue is.

Thanks!
thumbnail
Daniele Baggio, módosítva 10 év-val korábban

RE: ADT Template, how to use template key?

Expert Bejegyzések: 336 Csatlakozás dátuma: 2008.12.05. Legújabb bejegyzések
Ok, i have to try the steps you wrote me soon.

The test I am doing is not about web content but ADT in a custom portlet.
ADT in custom portlet works well, but I'am not able to include a template into another.

Do you think this is the same context of web content?
thumbnail
Eduardo P. García, módosítva 3 év-val korábban

RE: ADT Template, how to use template key?

Regular Member Bejegyzések: 157 Csatlakozás dátuma: 2012.03.16. Legújabb bejegyzések
Hi Daniele,

I think I see now what you're trying to do. Currently you cannot include an ADT template into another. As a workaround you can create a "generic" template (a template without any structure) and include it from your ADT template. These are the steps:

1. Go to Web Content > Manage > Templates
2. Add a new Template. Select no structure, just set the language (Velocity or Freemarker) and add your code.
3. Go to your ADT template and include the previously created template using the templatesPath variable and its templateKey.
4. Verify now that the portlet where you applied the ADT is rendered as a combination of the two templates.

IMPORTANT: The template context is determined by the portlet the ADT is rendered for. This means that your generic template should refer only to variables available in that template context. Normally you'd want to use only generally available variables (the ones listed under General Variables in the template editor) but you can use portlet specific variables (such as formattedContent for the Wiki) as long as you make sure this template is included only in ADTs for Wiki.

I hope this helps. Tell me if it works for you.

Thanks!
thumbnail
Alberto Glez, módosítva 9 év-val korábban

RE: ADT Template, how to use template key?

New Member Bejegyzések: 3 Csatlakozás dátuma: 2014.01.07. Legújabb bejegyzések
Thanks eduardo, this works fine for me, but the problem now is that in the imported template i've calls to estructure attributes, and this calls are not being called. So is there a way to make the context of the structure available? so i can access his attributes in the imported template?

Thanks and sorry for my bad english ;)
thumbnail
Joseph Toman, módosítva 5 év-val korábban

RE: ADT Template, how to use template key?

Junior Member Bejegyzések: 25 Csatlakozás dátuma: 2011.01.28. Legújabb bejegyzések
Eduardo,

Thanks for this. I was wondering how to get #include and #import to work.