Kentico - Display content of localization resource strings through repeater transformation - kentico

I have a custom pagetype with 1 text field where I keep re-usable html content to be included on other pages through a repeater. The transformation for the repeater has just 1 line of code <%# Eval("Content") %>.
I'm running into a situation where I want to use a resource string inside the content box together with other html content, something like {$ site.languages $}. However, when viewing, the pages displays this string {$ site.languages $} instead of the value of the resource string. Is it possible to display the resource string content in this case and how?

Try using
<%# Localize(Eval("Content")) %>

Try this:
ASCX transformations – call the Localize transformation method:
<%# Localize("Text containing localization expressions: {$stringKey$}") %>
Text / XML transformations – use localization string macro expressions or the
GetResourceString macro method:
{$stringKey$} - OR - {% GetResourceString("stringKey") %}

Related

how to add a CSS class using a Macro expression?

I need help setting up a CSS drop-down using macro. I created a new field, and under the data type I selected the dropdown. now back under transformation i paste the new field inside the class selector, but i dont see any of the class names i typed under form control.
<div class="alert {% AlertCssBackground %}" > <div>
There are a couple things you need to verify:
The drop-down field values are in the format
<value>;<display text>
For example:
red-bg;Red background
green-bg;Green background
What is stored in the database is the value. Which will be either red-bg or green-bg.
In your transformation, make sure you're using the proper type. If you're using macro syntax {% fieldName %} then you need to make sure you're using the Text/Html transformation type. If you're using the ascx format type <%# Eval("fieldName") %> then you need to use the ASCX transformation type.
If you stored the class name in the database field fieldName and you are using ascx page format then you can type <%# Eval("fieldName") %> in your transformation.

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

Kentico 9 search result transformation

We've noticed a bug when looking at French search results. in the CMS Desk, i've kept the Page Name in English for the French content. The issue is, these are showing on the French results page.
in the transformation, based off the default one, I present the clickable title like this:
<a href='<%# SearchResultUrl() %>' data-type="title" target="_blank" ><%#SearchHighlight(HTMLHelper.HTMLEncode(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), ""))), "<span class='highLight'>", "</span>")%></a>
Here's my thinking, if the Menu Caption is filled out, use that rather than title. How do i output DocumentMenuCaption without adjust the search fields on the menu page type?
I think my logic is, check if DocumentMenuCaption is emtpy, if it use, use Title.
You should be able to continue using GetNotEmpty and just pass in the DocumentMenuCaption first, something like this:
<%# GetNotEmpty(GetSearchValue("DocumentMenuCaption");Eval("Title")) %>
You may or may not need the "GetSearchValue" function, but that allows you to grab values from the object that may not be available in the default set of columns for the search results.
Alternatively, you should be able to use the IfEmpty() method:
<%# IfEmpty(GetSearchValue("DocumentMenuCaption"), Eval("Title"), GetSearchValue("DocumentMenuCaption")) %>
Both transformation methods taken from here (double check syntax on "GetNotEmpty" as there are different ways it's implemented: https://docs.kentico.com/k9/developing-websites/loading-and-displaying-data-on-websites/writing-transformations/reference-transformation-methods
You can read more about the search transformations here: https://docs.kentico.com/k9/configuring-kentico/setting-up-search-on-your-website/displaying-search-results-using-transformations

Kentico - Dynamic Page Title Not Display Correctly in Smart Search Results

I used {% CurrentDocument.DocumentName %} in the Metadata > page title field. The Title tag displays ok when viewing the article itself on the browser; however, when searching through Smart Search, the results output something like below in place of the Title. I'm not sure why, is there a way to fix this? Thanks!
{% CurrentDocument.DocumentName |(user)myLogin|(hash)9f2b69705f777e8a884a107dfb72f681d8eb99867b6967514dbdca851b7f4309%}
Note: This is for hundreds of article pages, and inheriting Page Title from Parent by using the macro work best for me.
What is your transformation for search results? How do you retrieve that value?
I can see two possible approaches to solve your issue:
go to page type -> search fields and select DocumentName as a value for Title field
adjust search results transformation and use <%# GetSearchValue("DocumentName") %> instead of <%# Eval("Title") %>
This is most likely because the user who signed the macro is not in the system any longer. I'd change the macro to simply read:
{%CurrentDocument.DocumentName#%}
Having the # at the end will say the macro does not need to be signed.

JSP out.println not rendering html tags

In a text area in jsp i am trying to dipslay some text in bold but it is not rendering the tags and displaying as it is:
e.g.
<% out.println("<b>"+Pattern+"</b>");%>
where String Pattern =ERROR
this shows as
<b>ERROR</b> .....in the veiw source it shows like <b>ERROR</b>
Is it not supposed to work this way ? what are other ways to make it bold.
Change it to:
<%= Pattern %>
its like printing it direct into the html Page
Just try <b><% out.println("+Pattern+");%></b>.

Resources