如何在liferay中使用freemarker显示平原的html

发布于 2025-01-28 16:17:26 字数 995 浏览 4 评论 0原文

在Liferay Portal 7.2中,我有Web内容的元素列表。对于此列表中的每个Web内容,我想在Web内容本身中获得HTML结果。

将ADT限制在一个带有默认模板的结构中,以列出它对我工作的每个Web内容:

<#list entries as entry>                    
        
    <#if hasCategoryId(entry, selectedYearCategoryId) &&
            hasCategoryId(entry, selectedTipoNormativaCategoryId)>
            

        <#assign assetRenderer = entry.getAssetRenderer()/>
        <#assign journalArticle = assetRenderer.getAssetObject()/>

            <@liferay_journal["journal-article"]
                articleId=journalArticle.getArticleId()
                groupId=journalArticle.getGroupId()/>                                    

    </#if>

</#list>

“ HASCATEGORYID”是一个自定义功能,并且此ADT嵌入式需要重新加载整个页面将参数传递到URL中。

我想知道我是否想使用Ajax进行此操作,并在 mvCrenderCommand mvcresourcececommand中进行此操作,它是否存在将Web内容转换为HTML的任何

方法

JournalArticle.getHTML(structureId, templateId);

In Liferay Portal 7.2, I have list of elements that are Web Contents. For each Web Content in this list I want to get the HTML result defined in the web content itself.

Having an ADT restricted to one structure with a default template, to list every Web Content it's working for me:

<#list entries as entry>                    
        
    <#if hasCategoryId(entry, selectedYearCategoryId) &&
            hasCategoryId(entry, selectedTipoNormativaCategoryId)>
            

        <#assign assetRenderer = entry.getAssetRenderer()/>
        <#assign journalArticle = assetRenderer.getAssetObject()/>

            <@liferay_journal["journal-article"]
                articleId=journalArticle.getArticleId()
                groupId=journalArticle.getGroupId()/>                                    

    </#if>

</#list>

"hasCategoryId" is a custom function and this ADT embedded needs to reload the entire page passing the parameteres to itself in the URL.

I was wondering if I want to do it using Ajax and do this stuff in a MVCRenderCommand MVCResourceCommand, exists any way to convert a Web Content into HTML giving structureId, articleId, ...

Something like:

JournalArticle.getHTML(structureId, templateId);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遥远的绿洲 2025-02-04 16:17:26

我认为您正在寻找这种方法,

    _journalArticleLocalService.getArticleDisplay(
                    themeDisplay.getScopeGroupId(), articleId, 
                    templateKey, null, themeDisplay.getLanguageId(), 
                    themeDisplay).getContent();

您可以在 docs

当您想使用AJAX调用调用此代码时,您可能应该使用Mvcresourcecommand。代码将是这样的:

package com.your.packace;

import com.liferay.journal.service.JournalArticleLocalService;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCResourceCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCResourceCommand;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ContentTypes;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.WebKeys;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

@Component(
        immediate = true,
        property = {
                "javax.portlet.name=" + YourPortletKeys.YOUR_PORTLET_NAME,
                "mvc.command.name=/your/command/name"
        },
        service = MVCResourceCommand.class
)
public class GetArticleDisplayMVCResourceCommand extends BaseMVCResourceCommand {

    @Override
    protected void doServeResource(
            ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

        ThemeDisplay themeDisplay =
                (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

        String articleId = ParamUtil.getString(resourceRequest, "articleId");
        String templateKey = ParamUtil.getString(resourceRequest, "templateKey");

        JSONObject response = JSONFactoryUtil.createJSONObject();

        String html = _journalArticleLocalService.getArticleDisplay(
                themeDisplay.getScopeGroupId(), articleId,
                templateKey, null, themeDisplay.getLanguageId(),
                themeDisplay).getContent();

        response.put("html", html);

        resourceResponse.setContentType(ContentTypes.APPLICATION_JSON);
        resourceResponse.getWriter().write(response.toString());
    }

    @Reference
    private JournalArticleLocalService _journalArticleLocalService;
}

我没有测试此代码,所以让我知道Somethig是否错了。

I think you are looking for this method

    _journalArticleLocalService.getArticleDisplay(
                    themeDisplay.getScopeGroupId(), articleId, 
                    templateKey, null, themeDisplay.getLanguageId(), 
                    themeDisplay).getContent();

you can see more about it on the docs.

As you want to call this code with an Ajax call, you should probably be using MVCResourceCommand. The code would be something like this:

package com.your.packace;

import com.liferay.journal.service.JournalArticleLocalService;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCResourceCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCResourceCommand;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ContentTypes;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.WebKeys;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

@Component(
        immediate = true,
        property = {
                "javax.portlet.name=" + YourPortletKeys.YOUR_PORTLET_NAME,
                "mvc.command.name=/your/command/name"
        },
        service = MVCResourceCommand.class
)
public class GetArticleDisplayMVCResourceCommand extends BaseMVCResourceCommand {

    @Override
    protected void doServeResource(
            ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

        ThemeDisplay themeDisplay =
                (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

        String articleId = ParamUtil.getString(resourceRequest, "articleId");
        String templateKey = ParamUtil.getString(resourceRequest, "templateKey");

        JSONObject response = JSONFactoryUtil.createJSONObject();

        String html = _journalArticleLocalService.getArticleDisplay(
                themeDisplay.getScopeGroupId(), articleId,
                templateKey, null, themeDisplay.getLanguageId(),
                themeDisplay).getContent();

        response.put("html", html);

        resourceResponse.setContentType(ContentTypes.APPLICATION_JSON);
        resourceResponse.getWriter().write(response.toString());
    }

    @Reference
    private JournalArticleLocalService _journalArticleLocalService;
}

I did not test this code, so let me know if somethig is wrong.

梦言归人 2025-02-04 16:17:26

如果您要进入Ajax,请使用。您可以轻松获取JSON或HTML的内容。

If you're going into Ajax, use the Headless API. You can easily fetch content as JSON or HTML.

苍暮颜 2025-02-04 16:17:26

抱歉,我对Ajax和MvCrenderCommand的引用感到有些困惑...

重读您的问题,我建议您简单地将TemplateKey添加到标签调用中,按 https://docs.liferay.com/dxp/dxp/apps/web-experience/7.0.0 .11/taglibdocs/liferay-journal/journal-article.html

类似:

<@liferay_journal["journal-article"]
            articleId=journalArticle.getArticleId()
            ddmTemplateKey="654321"
            groupId=journalArticle.getGroupId()/> 

Sorry, I got a bit confused by the references to Ajax and MVCRenderCommand...

Rereading your question I suggest that you simple add a templateKey to your tag invocation, as per https://docs.liferay.com/dxp/apps/web-experience/7.0.11/taglibdocs/liferay-journal/journal-article.html

Something like:

<@liferay_journal["journal-article"]
            articleId=journalArticle.getArticleId()
            ddmTemplateKey="654321"
            groupId=journalArticle.getGroupId()/> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文