Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Daniele Baggio
ADT Template, how to use template key?
September 9, 2013 12:30 AM
Answer

Daniele Baggio

Rank: Regular Member

Posts: 190

Join Date: December 5, 2008

Recent Posts



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?
Eduardo P. Garcia
RE: ADT Template, how to use template key?
September 16, 2013 3:01 AM
Answer

Eduardo P. Garcia

LIFERAY STAFF

Rank: Junior Member

Posts: 34

Join Date: March 15, 2012

Recent Posts

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:

1<#include "${templatesPath}/11514" />


Thanks!
Daniele Baggio
RE: ADT Template, how to use template key?
September 16, 2013 5:41 AM
Answer

Daniele Baggio

Rank: Regular Member

Posts: 190

Join Date: December 5, 2008

Recent Posts

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:
1
2<#include "${templatesPath}/16901" />


The result is:

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


p.s. I am using LF 6.2 beta 2
Eduardo P. Garcia
RE: ADT Template, how to use template key?
September 17, 2013 9:32 AM
Answer

Eduardo P. Garcia

LIFERAY STAFF

Rank: Junior Member

Posts: 34

Join Date: March 15, 2012

Recent Posts

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:

"Included template", with the content:

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


"Main template", with the content:

1<#include "${templatesPath}/12345" />
2
3<p>This is my main template</p>


Assuming that 12345 is the templateKey of the "Included template".

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:

1This is an included template
2This is my main template


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

Thanks!
Daniele Baggio
RE: ADT Template, how to use template key?
September 18, 2013 12:38 AM
Answer

Daniele Baggio

Rank: Regular Member

Posts: 190

Join Date: December 5, 2008

Recent Posts

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?
Eduardo P. Garcia
RE: ADT Template, how to use template key?
September 18, 2013 9:51 AM
Answer

Eduardo P. Garcia

LIFERAY STAFF

Rank: Junior Member

Posts: 34

Join Date: March 15, 2012

Recent Posts

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!
Alberto Glez
RE: ADT Template, how to use template key?
September 5, 2014 3:44 AM
Answer

Alberto Glez

Rank: New Member

Posts: 3

Join Date: January 7, 2014

Recent Posts

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 ;)