咨询Liferay 7.2单篇博客条目HTML及模板的修改方法
Hey there! Since you’ve already nailed modifying the blog entry list template in Liferay 7.2, customizing the single blog entry template uses a similar workflow—let me walk you through the two main approaches, depending on whether you need site-specific or global changes:
Customizing Single Blog Entry Templates in Liferay 7.2
1. Site/Instance-Specific Customization (No Code Deployment Needed)
This is the quickest way if you only need the change for one site:
- Head to Site Administration → Content & Data → Blogs.
- Click the three-dot Options menu at the top right, then select Templates.
- You’ll see two template types here: Blogs Entry (this is the single entry template you’re looking for) and Blogs Entry List (the one you already modified).
- Either edit the default "Basic" template (click Edit) or create a new template from scratch if you want to keep the original intact.
- Use the built-in FreeMarker editor to adjust the HTML structure, add/remove elements (like author portraits, publish dates, tags), or rearrange content. For example, if you want to hide the author’s name, you can comment out or delete the line that renders
${entry.getUserName()}. - Save your changes, then navigate to any single blog entry—you’ll see your updates live right away.
2. Global Customization (For All Sites)
If you need this tweak across your entire Liferay instance, you can override the default template via a theme or OSGi module:
Option A: Theme Override
- In your theme’s
src/templatesdirectory, create a file namedblogs_entry.ftl. - Copy the default FreeMarker code (you can grab this from the built-in template editor mentioned above) into this file.
- Modify the code to fit your needs—add custom CSS classes, reorder content blocks, or inject additional data.
- Deploy your theme, and Liferay will automatically use this template for all blog entries across all sites.
Option B: OSGi Template Module
- Create a new OSGi module with a
resources/META-INF/resources/templatesfolder. - Place your custom
blogs_entry.ftlfile inside this folder. - Register the template using a
TemplateContributorcomponent or configure it in yourbnd.bndfile to override the default. This method is more flexible if you want to switch templates dynamically, but requires basic OSGi development knowledge.
Quick Pro Tips
- Always test changes in a staging environment first to avoid breaking your production site.
- Use Liferay’s built-in utility methods (like
${htmlUtil.escape()}) to keep your template secure and prevent XSS vulnerabilities. - If you need to add custom fields to blog entries, define them in Site Administration → Content & Data → Structures, then reference them in your template with
${entry.getExpandoBridge().getAttribute("yourCustomFieldName")}.
内容的提问来源于stack exchange,提问作者MarioProject
相关产品推荐
相关产品推荐

