Kentico CMS: Add a class attribute to the html tag in a Kentico Masterpage - content-management-system

How do you edit the HTML tag in a Kentico CMS Masterpage, i.e. to add a class attribute?
Currently I have this:
But I want:
<!DOCTYPE html>
<html class="myClass">
<head>
<title>
From the screenshot you can see that the HTML tag is not editable.
Is there a way to edit the html tag or tell Kentico to write a class attribute to the html tag?

I have found one solution:
I manually added a class attribute to the HTML tag in this file:-
<solution>/CMSPages/PortalTemplate.aspx

You can also use the "Head HTML" web part on your page template(s).

It is quite disappointing that Kentico still does not support this out of the box. A request to be able to modify the <html> tag directly from code has been filed: http://ideas.kentico.com/forums/239189-kentico-product-ideas/suggestions/5947264-ability-to-modify-page-head-section-and-html-tag
In the meantime use the following solutions:
Portal Engine
I solved this the following way, based on Dave Haigh suggestion. In the file /CMSPages/PortalTemplate.aspx change the following line:
<html xmlns="http://www.w3.org/1999/xhtml" <%=XmlNamespace%>
lang="<%=CMSContext.PreferredCultureCode%>">
ASPX Engine
In your master page, add the following snippet to your code behind file:
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (CurrentDocument != null)
{
CMS.UIControls.ContentPage page= this.Page as CMS.UIControls.ContentPage;
if (page != null)
{
string lang= CMS.Localization.LocalizationContext.CurrentCulture.CultureCode;
page.XmlNamespace += " lang=\"" + lang + "\"";
}
}
}
</script>
Source: http://devnet.kentico.com/questions/kentico-9-how-to-define-language-in-html

Related

eclipse stops responding while running a .jsp file

i have created a basic dynamic web project in eclipse.
my jsp file contains following code
<html>
<head>
<title>Insert title here</title>
</head>
<body>
this is the sum of 5 and 3 <%com.testing.SumOfNumbers.addTwoNumbers(3,5); %>
</body>
</html>
and in package "com.testing" i have created SumOfNumbers class with addTwoNumbers method.
package com.testing;
public class SumOfNumbers {
public static int addTwoNumbers(int a,int b)
{
return a+b;
}
}
i have downloaded tomcat v10.0 server.
I tried several times but same result. I don't know where the problem is ,is it in tomcat server or eclipse bug?
thanks in advance.
It's unlikely to be your code, although you're using a scriptlet instead of an expression, so the sum won't be in the output like you seem to expect.
https://wiki.eclipse.org/How_to_report_a_deadlock includes directions on how to get a stack dump to see what's going on.

How to use Sidebar Search Plugin in AdminLTE v3

In my project I'm using AdminLTE from https://cdnjs.cloudflare.com/ajax/libs/admin-lte/3.0.5/js/adminlte.min.js but it doesn't load SidebarSearch.js on it.
How do I use this plugin in my project? Does anyone have a simple example to show me, because in the documentation itself it is not clear how to use this plugin.
mainly at this point:
$('[data-widget="sidebar-search"]').SidebarSearch('toggle')
Where in HTML / JS should I put this line of code?
To answer your question, simply add it in a script tag before the closing body tag of your page, example:
<html>
<head>
...
</head>
<body>
...
<script>
$(document).ready(function()
{
// Example to toggle dropdown list of the search bar
$('[data-widget="sidebar-search"]').SidebarSearch('toggle');
// Example to initialize the plugin with options
let options = {
arrowSign: '/',
minLength: 2,
highlightClass: 'text-yellow',
notFoundText: 'No results'
...
};
("[data-widget="sidebar-search"]").SidebarSearch(options);
});
</script>
</body>
</html>
However this method seems to return duplicate results.
Preferred method
Just add the options as attributes beside data-widget="sidebar-search".
It should look like this data-not-found-text='No results' data-highlight-class='text-yellow' data-min-length='2'
adminLTE documentation

ZK Textbox content containing <html> tag

When I put the string '' into a ZK Textbox, that is
<textbox value="<html>" />
it causes a JavaScript error in the browser
Uncaught SyntaxError: Unexpected token ILLEGAL
and I can see in the developer tools of the browser that the generated JS code is really incomplete:
zkmx(
[0,'g2JQ_',{dt:'z_y20',cu:'\x2Fdtag',uu:'\x2Fdtag\x2Fzkau',ru:'\x2Fzul\x2Fcomponent\x2Fmenu.zul',style:'width\x3A100\x25\x3B',ct:true},[
...
['zul.inp.Textbox','g2JQp7',{id:'tb',$$0onBlur:true,$$0onSwipe:true,$$0onError:true,$$0onAfterSize:true,$$0onChanging:true,$$1onChange:true,$$1onSelection:true,$$0onFocus:true,width:'500px',style:'font-size:11px;',_value:'
</div>
How can I escape the content of the textbox so that I can display any HTML code in the textbox?
I tried
Replace '<' with '> but then > is displayed.
I also tried
<![CDATA[ <html></html>]]>
but then it was literally displayed, that is, also the
<![CDATA[
UPDATE
It is somehow due to the fact that we have JSPs containing several ZK pages.
And the exact content what causes problem is the closing HTML tag
</html>
The workaround is the following:
Events.echoEvent("onLater", txtDescription, txtDescription);
txtDescription.addEventListener("onLater", new EventListener<Event>() {
#Override
public void onEvent(Event event) throws Exception {
txtDescription.setValue("<html>...</html>");
}
});
Normally you should get values from your composer or viewmodel, and then this problem doesn't exist.
If you want to do it in the zul, you can make a parameter in zscript like this :
<zscript>
<![CDATA[
String a = "<html>";
]]>
</zscript>
<textbox value="${a}" />
Here I created a fiddle so you can test it.
Many time we have saved HTML code in database but when we are going to display that saved value in zk page it show HTML code as well with data .
To resolve this issue we have to use HTML escape there are plenty of way to fix this
You can do it on Java side as well zul page and here is simple way how you can achieve in the zul page
<html>
<![CDATA[
${vm.accessYourValue}
]]>
</html>

How to navigate DOM from Wicket

I wonder if it is possible to modify the HTML code of the parent of a wicket component in the Java code to modify its attribute without making it a component in wicket. For example, I would like to add active to the li tag from Java.
<li>
<a wicket:id="home" href="#">
<i class="icon-home"></i>
<span>Home</span>
</a>
</li>
and the say add an Attribute to that parent without referencing it in code as a component.
I don't think this is possible, it would be completely against the modular nature of Wicket. (Not to mention the fact that pages are actually rendered as a stream, there's no DOM tree built.)
Components in Wicket shouldn't depend on what's outside of them. What if you want to change the logic of active/inactive controls? Or, in a more likely scenario, you just want to change the markup. Or if you just want to unit test your component without any surrounding markup.
Wicket was designed to avoid these "spooky actions at a distance", to create components that are genuinely testable on their own.
You need a component that encapsulates the entire list, which keeps track of which of its items is active (via its model). It might seem at first like a lot of work but when you look at the result, you'll realise how much easier it is to understand what's going on.
You can do it using javascript. In this example I overrided the renderHead() of the link, but it can also be done with a Behavior.
public class TestPage extends WebPage {
public TestPage(final PageParameters parameters) {
super(parameters);
add(new AjaxLink<Void>("link") {
boolean active = false;
#Override
public void onClick(AjaxRequestTarget target) {
active = !active;
target.add(this);
}
#Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
String addOrRemove = (active) ? ".addClass('active')" : ".removeClass('active')";
response.render(OnDomReadyHeaderItem.forScript("$('#" + getMarkupId() + "').parent('li')" + addOrRemove + ";"));
}
});
}
}
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<style type="text/css">
li.active {background-color: red;}
</style>
</head>
<body>
<ul>
<li><a wicket:id="link">TOGGLE</a></li>
</ul>
</body>
</html>
Yes, it will couple the code to the markup, but this is not always a problem. If you feel you are copying and pasting this code over and over, consider creating a proper component :)

Testing Wicket panels with constructor arguments

I got a page with several panels that takes several parameters in their constructors.
One of them being a menu that takes a list for the different buttons in the menu.
I've tried to test it as components but get a null pointer exception. Using a dummy page and creating the panel on the dummy page works.
I'm not entirely happy with this approach since it introduces a lot of new code in my tests and more possibilities for errors.
Is there a better way of testing panels that takes arguments in their constructor?
Sure thing:
The code that gives an null pointer error:
public void testVisitPanel(){
VisitPanel v = new VisitPanel("visitPanel");
tester.startComponent(v);
tester.assertContains("DATE");
}
The panel
public VisitPanel(String id) {
super(id);
add( new Label("visitDate", "DATE"));
add( new Label("visitStage", "VISIT SIGNED"));
}
And the html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.sourceforge.net/"
xml:lang="en"
lang="en">
<wicket:head>
</wicket:head>
<body>
<wicket:panel>
<span wicket:id="visitDate">VISIT DATE</span>
<span wicket:id="visitStage">STAGE</span>
</wicket:panel>
</body>
</html>
If you're using Wicket 1.4, you probably want wicketTester.startPanel.
What I do is create an implementation of ITestPanelSource in the test, doing something like:
private class TestPanelSource implements ITestPanelSource {
private static final long serialVersionUID = 1L;
public Panel getTestPanel(String panelId) {
return new MyPanel(panelId, myArg1, myArg2);
}
}
with the myArgN being fields in the test class (frequently mocks) that suit the constructor, and then call it in the test or in a setUp method with
wicketTester.startPanel(new TestPanelSource());
This is basically doing some of the DummyPage work for you, so it may not be that far from what you're doing now, but might at least save on implementation of dummy pages for test infrastructure.
In Wicket 1.5, this is deprecated in favor the component testing that you referenced in the question. That should also work, so it might be worthwhile to post some actual code that is giving you trouble with that technique.