Can't Inherit Odoo theme template - odoo-13

I have Base theme called theme_test
Here is the template code(this template is added in manifest's data).
<template id="product_catg_test" name="Product Category">
<t t-if="categories">
<code for print category>
</t>
</template>
So I have created an extended module called test_theme_extended and tried two inherit approach to replace the t-if condition
First Approach(I added this file in data in the manifest)
<template id="product_catg_test_extended" inherit_id="theme_test.product_catg_test" name="Test">
<xpath expr="//t[#t-if='categories']" position="replace"></xpath>
</template>
This first approach gives me an error
odoo.tools.convert.ParseError: "Element '' cannot be located in parent view
Second Approach(I added this file in QWEB in the manifest)
<t t-extend="theme_test.product_catg_test">
<t t-jquery="t[t-if='categories']" t-operation="replace"/>
</t>
This also not working.
I am thinking that the main view created from the theme and it has no external ID that's why I face this issue. But how can I inherit the base theme view in extended module?

If you are inheriting a theme it has to be from another theme, or use a record instead of template.
Defining a theme, as with a theme prefix and in the thema category
Since a module-theme creates the views in theme ir_ui_view and creates copies without XMLID in ir_ui_view
and a normal module creates the views in ir_ui_view
So if from a normal module (ir_ui_view) you want to modify a view-theme (theme_ir_ui_view) then literally it will not find the element because it is in another table
but if you still want to try you can do the inheritance in this way, inheriting the copies that do not have the XML so you have to do the inheritance by the key
<record id="product_catg_test_extended" model="ir.ui.view">
<field name="name">product_catg_test_extended</field>
<field name="inherit_id" search="[('key', '=', 'theme_test.product_catg_test')]"/>
<field name="type">qweb</field>
<field name="key">test_theme_extended.product_catg_test_extended</field>
<field name="arch" type="xml">
<xpath expr="//t[#t-if='categories']" position="replace"></xpath>
</field>
</record>

currently I'm struggeling with the exact same problem. So far when debugging the code responsible for the lookup I wondered why the content of the parent view is not the same as the xml shows.
Long story short: The templates from theme modules are NOT stored as ir.ui.view but as theme.ir.ui.view. The code will lookup with the wrong ID as it expects a regular view - either finding the wrong regular view or finding nothing.
Unfortunately I did not find any solution to modify a theme.ir.ui.view - if someone has a solution I would really appreciate if she/he shares it with us.
It seems the only way to modify a theme is to edit the original xml files.
UPDATE:
I've tried to work with a different approach like I inherit form views (<record model='theme.ir.ui.view />) but this only created the record in the table theme_ir_ui_view but did not triggered the inheritance mechanisms.
For now I've created a new xml inside the theme I want to modify and have to live with that. Maybe a custom module named 'theme_XXX' could also inherit a theme template but I have to go on with my project.

Related

Liferay: localize layout template names

I have written a maven module, which contains my custom layout for liferay. The layout works fine but I also want it's name to be translated in a few languages.
Here's my liferay-layout-templates.xml file:
<?xml version="1.0"?>
<!DOCTYPE layout-templates PUBLIC "-//Liferay//DTD Layout Templates 6.2.0//EN" "http://www.liferay.com/dtd/liferay-layout-templates_6_2_0.dtd">
<layout-templates>
<custom>
<layout-template id="2_columns_layout-75_25" name="myLayout">
<template-path>/2_columns_layout-75_25/2_columns_75_25.tpl</template-path>
<wap-template-path>/2_columns_layout-75_25/2_columns_75_25.wap.tpl</wap-template-path>
<thumbnail-path>/2_columns_layout-75_25/2_columns_75_25.png</thumbnail-path>
</layout-template>
</custom>
</layout-templates>
I tried to delete name attribute and add language keys(which were the same to my template id) and values to my hook module, but it didn't work.
At first I was inclined to state that there's no built-in way to localize layout templates. However, I've looked up the JSP in question (in Liferay's html/portlet/layouts_admin/layout/layout_templates_list.jsp) and found the following line (shortened and edited):
<%= HtmlUtil.escape(LanguageUtil.get(locale,
"layout-template-" + layoutTemplateName, layoutTemplateName)) %>
So it looks like the localization keys that you'll need to use for translating your layout-template's name needs to be starting with "layout-template-" followed by the layout template's own name, e.g. given the xml from your question: layout-template-myLayout=My first localized layout template

Advanced Orchard Theming - Object Model vs Placement.info?

I have been tasked with converting a design heavy, fairly advanced HTML template for a site into an Orchard theme and I am struggling with the best way to accomplish certain things. The theme is built on bootstrap and is a modern responsive HTML template like you might find on ThemeForest or something. The site will have a number of content types (staff members, portfolio items, partners, etc.) and will need a number of templates. The content types will have a large number of fields (upwards of a dozen) inside of custom content parts.
Based on what I have read the proper way to do theming in Orchard is using placement.info in combination with alternates, wrappers, etc. This gracefully handles if parts or properties are added/removed. However, this technique is quickly becoming overwhelming, since I have to declare the name and order of every field/part in the placement.info for every content type, and every display type of that content type. Each field of each content type then needs to be wrapped in very specific html. This creates an issue because a single page can be split out into potentially a couple dozen views, with HTML tags opening in one view and closing in another.
The best work around for this I have found is to basically ignore the placement.info file and build templates just by traversing the object model. So basically, for a portfolio page, I would copy in the template HTML I have and then replace the text values with values from the model. This might look something like:
<li class="#Display(Model.ContentItem.PortfolioPart.PortfolioCore.Value.ToLower())">
<a href="#Url.ItemDisplayUrl(contentItem)" >
#foreach (var media in Model.ContentItem.PortfolioPart.PortfolioImage.MediaParts)
{
<img src="#Display(media.MediaUrl)" />
}
<span class="type">#Display(Model.ContentItem.PortfolioPart.PortfolioCoreArea.Value)</span>
<span class="portfolio-item-content">
<span class="header">#Display(Model.ContentItem.TitlePart.Title)</span>
<span class="body">
<p>
#Display(Model.ContentItem.PortfolioPart.PortfolioTagline.Value)
</p>
</span>
</span>
</a>
</li>
The benefit with this method is that I can apply all of the values in a couple of views and it's more readable. Obviously the problem with this is that if any properties or parts are removed, the template breaks.
Is there a way in Orchard to have the best of both worlds? I can't have a wrapper or template for every field - this would end up potentially hundreds of fields by the end. I also might need to display content types in multiple places with different views - each field would then require a whole new set of wrappers or alternates for every projection.
Please let me know if I'm missing anything or if there is a better way to do this besides manually traversing to the properties I need. I need a way to be able to easily plug in properties into very specific html.
My final thought was to use very specific templates for custom content types using the object model but still provide good general templates/placement.info file so that general Orchard content is flexible but the custom content types have to stay how they are.
Side thought - I guess another option would be to wrap any code that accesses a property directly in a try catch block or some kind of error handler helper, but that doesn't seem like a "best practice".
I think the techniques in this article are what you're looking for: http://weblogs.asp.net/bleroy/archive/2013/02/13/easy-content-templates-for-orchard-take-2.aspx

Link article from a module parameter (field modal_article)

I want to develope a joomla! 2.5 module on which the admin could select an article so that the selected article will be displayed as a link in the frontend. The params of a module are declare in the modulename.xml file, so I want to know if there is a field type like the one that lets you select an article when you create a menu item to show a single article.
here is the xml file
<fieldset name="basic" addfieldpath="/modules/mod_ctfapartados/elements/">
<field name="" type="article" default="0" label="MOD_APARTADOS_LINK_ONE_LABEL"
description="MOD_APARTADOS_LINK_ONE_DESC"
for some reasons i am not able to edit the code in my previous answer so here is the revised part of code
<fieldset
name="request"
addfieldpath="/administrator/components/com_content/models/fields">
<field
name="article_id"
type="modal_article"
label="label"
required="true"
description="desc"/>
</fieldset>
create a folder in your module with name "elements"
copy the file article.php from joomlaroot\administrator\components\com_content\elements
and place it in your modules elements folder
then in your xml add these lines

what is the easiest way to filter articles in liferay theme

Excuse me if I'm asking silly or easy question, but I just can't figure it out.
So, I have a theme, I want to render only portlets, skipping any journal articles.
Which is the most appropriate way to do it?
In your theme's resources, there is a portlet.vm template available in the _diffs/template directory. This template allows you to override the default presentation of portlets in general (e.g. change the configuration icons, remove the title bar, ...).
However, inside portlet.vm Liferay injects a predefined variable called $portletDisplay. This is an instance of the com.liferay.portal.theme.PortletDisplay class and represents the portlet that is currently printed.
You can use the $portletDisplay.portletName attribute to check for 56, which is the ID for all Web Content Display portlets. So, in short, encapsulate the parent <div> inside portlet.vm with the following condition:
#if($portletDisplay.portletName == '56')
<div class="portlet" ...>
...
</div>
#end

Is it possible to format a NumberField in a page layout?

I'm developing a SharePoint publishing site and setting up its content types and page layouts. I need to display the value for a Year field with type Number. The markup currently is:
<SharePointWebControls:NumberField FieldName="Year" runat="server" id="Year" />
The problem with the default behaviour is that it shows each number with a comma, e.g. "2,009" instead of "2009". Is there a way I can set some sort of String.Format syntax on the field to make it display correctly?
I tried creating a new rendering template which looks like this:
<SharePoint:RenderingTemplate ID="YearNumberField" runat="server">
<Template>
<SharePoint:FormField ID="TextField" runat="server"/>
</Template>
</SharePoint:RenderingTemplate>
... but there doesn't appear to be any 'Format' property on the FormField object.
Thanks for any help.
Update:
I tried wrapping the SharePoint:FormField tag inside SharePoint:FormattedString. Unfortunately the field was not formatted, same results as this question.
The issue is that the rendering template must use FormField. This always renders the value in the format: 1,989 . To resolve this the rendered text needs to be trapped and altered to get the desired output. Here are two approaches to resolving this:
1. Write a custom control inherited from NumberField
The RenderFieldForDisplay and RenderFieldForInput methods can be overridden to provide the desired output. Additional properties can be added to the control to describe additional behaviour.
Pros: No changes to rendering templates required.
2. Write a custom control for use in the rendering template
A control that (for example) uses regular expressions to alter text can wrap around the FormField control.
<SharePoint:RenderingTemplate ID="YearField" runat="server">
<Template>
<RX:RegexManipulatorControl runat="server"
Mode="Replace"
Expression=","
Replacement="">
<SharePoint:FormField runat="server"/>
</RX:RegexManipulatorControl>
</Template>
</SharePoint:RenderingTemplate>
Pros: Generic solution can be used for any type of field.
from Just Another SharePoint Blog
Open the list view in SharePoint
Designer.
Right click on the data view web part.
(the list)
Select Convert to XSLT Data View
Click on the number field you would
like to format
A > will appear showing Data Field,
Format As
Click on the link below Format As -
Number formatting options
Under Options deselect Use 1000
separator
Click OK
Save your changes and hit F12 to
preview

Resources