Use attributes without renderRequest in a FreemarkerPortletUse attributes without renderRequest in a FreemarkerPortlethttps://liferay.dev/c/message_boards/find_thread?p_l_id=119785333&threadId=1216786642024-03-28T22:35:42Z2024-03-28T22:35:42ZRE: RE: Use attributes without renderRequest in a FreemarkerPortletAdrián Polhttps://liferay.dev/c/message_boards/find_message?p_l_id=119785333&messageId=1216843192023-03-31T14:51:15Z2023-03-31T09:04:08Z<p>Good David, thanks for your answer, we are using a portlet for
Liferay 7.3 but we have modified some things:<br /> - We have changed
the MVCPortlet to FreeMarkerPortlet.<br /> - We have modified the bnd
to integrate the tlds.</p>
<p>In short, we have replicated a little bit the portlet of this Blade
example.<br /> https://github.com/liferay/liferay-blade-samples/tree/master/liferay-workspace/apps/freemarker-portlet</p>
<p>I put here a little code to demonstrate how we have the module</p>
<p>Portlet:</p>
<table>
<tbody>
<tr>
<td id="LC44">public class BladeFreeMarkerPortlet extends
FreeMarkerPortlet {</td></tr>
<tr>
<td id="L45"> </td><td id="LC45">}</td></tr></tbody></table>
<p>MVCRender:</p>
<p>//@formatter:off<br /> @Component(<br /> immediate =
true, <br /> property = { <br />
"javax.portlet.name=" +
BladeFreeMarkerPortlet.PORTLETID, <br />
"mvc.command.name=/",<br />
"mvc.command.name=/portlet_freemarker/view" <br />
}, <br /> service = MVCRenderCommand.class<br />
)<br /> //@formatter:on<br /> public class
FreemarkerPortletViewMVCRenderCommand implements MVCRenderCommand {</p>
<p> @Override<br /> public String render(RenderRequest
renderRequest, RenderResponse renderResponse) throws PortletException
{<br /> final ThemeDisplay themeDisplay = (ThemeDisplay)
renderRequest.getAttribute(WebKeys.THEME_DISPLAY);<br />
renderRequest.setAttribute("exampleVar", "Emample View
Var");<br /> return "templates/view.ftl";<br />
}</p>
<p>}</p>
<p>View:</p>
<p><#include "init.ftl"></p>
<p><h1>Freemarker Portlet</h1></p>
<p><p><br /> <b class="redBackground"><br />
<@liferay_ui["message"]
key="example.text.caption" /><br /> </b><br />
${exampleVar} <-- Error<br /> <br /> </p></p>
<p>Would we have to make any modifications to FreeMarkerPortlet?</p>Adrián Pol2023-03-31T09:04:08ZRE: Use attributes without renderRequest in a FreemarkerPortletDavid H Nebingerhttps://liferay.dev/c/message_boards/find_message?p_l_id=119785333&messageId=1216834372023-03-30T15:30:19Z2023-03-30T15:30:18Z<p>Wow, I didn't think anyone was doing FM portlets anymore...</p>
<p>Liferay uses FM for themes and template handling (for web structures,
ADTs, etc) and it uses TemplateContextContributors, but these are
really just wrappers that are used when initializing the FM context
object to inject values and services into the context so they are
available to FM.</p>
<p>I don't know how you're getting FM to handle the rendering of your
panel, but at some point you're going to be creating the context
object to pass to FM to use to render the template (just like the
renderRequest is being injected), so you just have to find out how
that context is being created and then the way to inject your values
and services into the context.</p>
<p>I could help you with this, but most of the details about how you're
building your portlet weren't provided, so this is the best I can do
at the moment.</p>David H Nebinger2023-03-30T15:30:18ZUse attributes without renderRequest in a FreemarkerPortletAdrián Polhttps://liferay.dev/c/message_boards/find_message?p_l_id=119785333&messageId=1216786632023-03-23T18:15:54Z2023-03-23T15:51:26Z<p>Hello! I am testing a portlet with the views in Freemarker and for
now everything is going great, doing some research on the forum I have
seen that in order to pass objects to the view we have to use
renderRest.setAttribute("test", test) (to send it) and
renderRequest.getAttribute("test") (to handle it in the ftl).</p>
<p>is there a way to avoid using the renderRequest.getAttribute and
directly put the object(${test}) as in the Templates or as in a
Liferay portlet of Spring type?</p>
<p> </p>
<p>
<img alt="" src="/documents/d/guest/captura-4-png?imagePreview=1" />
<br /> </p>
<p>Thank yo