How to insert dynamic text into a Wicket page - wicket

I have a page like this:
<html>
<body>
Foo
</body>
</html>
I want to use Wicket to replace the word "Foo" with "Bar", like this:
<html>
<body>
Bar
</body>
</html>
I cannot figure out how to do that. I don't want any HTML escaping on "Bar", and I don't want any tags placed around it.

Welcome to Wicket!
You need to use a Label component for the dynamic text. See http://wicket.apache.org/guide/guide/helloWorld.html#helloWorld_3. Or just create the application with the Maven archetype (http://wicket.apache.org/start/quickstart.html) - it has a label for the version of Wicket. Just replace the text with "Bar"

Related

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

Polymer data bind without dom-bind

I have a polymer element <my-element> with a computed property myProperty. I need to bind myProperty to another place in the HTML page, so I can't put it inside a dom-bind template
Here's what I mean
<html>
<body>
<div>
<my-element my-property="{{myProperty}}"></my-element>
</div>
<!--somewhere deep inside another part of the document-->
<div>
<h4>myProperty = </h4><span>[[myProperty]]</span>
<div>
</body>
</html>
I cannot wrap my-element and the usage of [[myProperty]] in a dom-bind template as this would result in nearly the entire document being enclosed in this. Attempting to use the bind as it is results in myProperty = [[myProperty]] being displayed, not the value of [[myProperty]].
Is there some way to have behaviour similar to data binding but usable across the whole HTML document? (In the future there might also be a case where [[myProperty]] is used inside an attribute such as <my-second-element my-property="[[myProperty]]">). Or if both occurences are wrapped individually in dom-bind templates is there some way to make the bind global?
Thanks in advance
Not sure why you wouldn't be able to do like this:
<head>
...
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
...
</head>
<html>
<body>
<template is="dom-bind" id="app">
<div>
<my-element my-property="{{myProperty}}"></my-element>
</div>
<!--somewhere deep inside another part of the document-->
<div>
<h4>myProperty = </h4><span>[[myProperty]]</span>
<div>
</template>
</body>
</html>
This is totally doable. If myProperty changes inside my-element it would also change in "this" html-document. There also wouldn't be a problem adding your second element:
<my-second-element my-property="[[myProperty]]">
Unless you're missing to tell us some specific behavior that you want, this should be what you want. :)

custom tag in HTML and parser with php

i have a problem and need your help.
i want use my custom tag in my script code like [tag] and analyze all html code then parser codes and Replace these tags with php code or my output world and echo my output
a simple code :
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>[MY_PAGE_TITLE]</title>
</head>
<header></header>
<div class="left">[MY_WEBSITE_LEFT_SIDEBAR_INFORMATION]</div>
<article>[MY_WEBSITE_ARTICLE]</article>
<div class="right">[MY_WEBSITE_RIGHT_SIDEBAR_INFORMATION]</div>
<footer></footer>
<body>
</body>
</html>
my first tag [MY_PAGE_TITLE] should be replaced with one world like "my website"
i want use this for my language website.
i get this word from a array like :
mylangarray [
MY_PAGE_TITLE="my website"
]
but for my any other tag i want load some module to left or right sidebar or load some article from my DB
How can I do this?
i solved my problem.
if you have this problem, you can use this method.
step1: you define your custom tag in your main view file and then in the server side with PHP ob_start function run output buffer then require or require_once or include or include_once your file.
now with define a variable and ob_get_contents function in PHP, store all file code in a variable. like this:
$html = ob_get_contents();
now you have all view file in a variable.
you can clean your buffer with ob_end_clean function.
example:
ob_start();
require_once 'mainViewFile.php';
$html = ob_get_contents();
ob_end_clean();
step2: you can use str_replace funcation for replace your defined custom tag with your new data.
$leftSideBarInformation = 'We stored left bar information in this variable!';
$html = str_replace('[MY_WEBSITE_LEFT_SIDEBAR_INFORMATION]', $leftSideBarInformation, $html);
if you have array of custom tag you can use a foreach loop.

A template as a template parameter in a play 2 views

I would like to define some templates in play 2 which takes an other template as a parameter:
#aTemplate(otherTemplate())
I think that should be possible in scala, right?
How would look like the parameter definition in the otherTemplate()? I should also have a default value in it. I'm thinking of something like that:
#(template: PlayScalaViewTemplate = defaultTemplate())
Thanks!
Yes you can. It's very simple once you discover that Play templates are just functions.
The higher order template (the one that gets the simple template as parameter) would look like this:
higherOrder.scala.html:
#(template: Html => Html)
<html>
<head><title>Page</title></head>
<body>
#template {
<p>This is rendered within the template passed as parameter</p>
}
</body>
</html>
So, if you have a simple sub-template like
simple.scala.html:
#(content: Html)
<div>
<p>This is the template</p>
#content
</div>
you would apply the template in the controller like so:
def index = Action {
Ok(views.html.higherOrder(html => views.html.simple(html)))
}
The result would be:
<html>
<head><title>Page</title></head>
<body>
<div>
<p>This is the template</p>
<p>This is rendered within the template passed as parameter</p>
</div>
</body>
</html>
So, scala templates are ultimately functions so you can compose them like functions.

Changing <title> with Lift

Is it possible to dynamically switch the title of a page that is served by Lift without having to write an extra snippet for that particular case?
One option is of course <lift:mySnippet><title>Default Title</title></lift:mySnippet> but I thought there might be an option along the lines of <head_merge><title>New Title</title></head_merge> (which inserts a second title node).
I do not like the first approach since I do not want to stick all the title generation logic into a single snippet and ask what kind of page I am on etc.
Have you tried to use templates?
You can define template in templates-hidden/default.html like this:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/">
<head>
<title>
<lift:bind name="title" />
</title>
...
</head>
<body>
<lift:bind name="content" />
</body>
</html>
And use it in index.html for example:
<lift:surround with="default">
<lift:bind-at name="title">Home</lift:bind-at>
<lift:bind-at name="content">
my content
</lift:bind-at>
</lift:surround>
You can find more information about templates here:
http://www.assembla.com/spaces/liftweb/wiki?id=liftweb&wiki_id=Templates_and_Binding
One way is to use the Menu.title snippet.
In bootstrap/liftweb/Boot.scala you define the sitemap with page names:
class Boot {
def boot {
// ...
def sitemap = SiteMap(
Menu.i("Home") / "index",
Menu.i("About") / "about")
// ...
}
}
In templates-hidden/default.html you use the snippet:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/">
<head>
...
<title class="lift:Menu.title">AppName:</title>
...
Then page titles will be: "AppName: Home" and "AppName: About". This is nice if you use
<span class="lift:Menu.builder"></span>
to build the menu, because page titles will be the same used in the menu.
Another approach is to use head merge and define the title in the page's html. For this to work, you have to remove the <title> tag from templates-hidden/default.html and put an <head> or <head_merge> tag in your content block:
<!DOCTYPE html>
<html>
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">
<head_merge>
<title>TITLE OF THIS PAGE HERE</title>
</head_merge>
...