I trying to use Spring's localization bundle with Thymeleaf templates. It works well if it is used in normal templates, but fails if I apply th:include attribute at container tag.
I put the view code to Gist: https://gist.github.com/hron84/386bbf855148a601a3dc
The problematic localization is at line 4 and line 10. In the line 10 I see the correct expansion ("New machine") but in line 4, i just get "null" as the page title.
Could you please point me what do I wrong?
As Martin says, your th:include is replacing your title tag, you should do somthing like this:
<head>
<title th:text="#{page.title.machine.new}"> </title>
<dif th:include="widgets/_head :: head" th:remove="tag"></dif>
</head>
The th:remove="tag" will remove the dif tag.
The Thymeleaf website has some usefull documentation about the th:include and th:replace tags.
With th:include your are replacing the inner conten, ie the title tag, with the content fetched from the fragment. As you did not post the head fragment template i cannot give you more hints for that one. I suspect your title tag in the head fragment is doing something different for the title tag?
Related
I'm currently going thru a tutorial on Scrapy. Encountering the following issue when using xpath to filter out certain tag elements from an html file for example.
<html>
<head>
<title>Title of the page</title>
</head>
<body>
<h1>H1 Tag</h1>
<h2>H2 Tag with link</h2>
<p>First Paragraph</p>
<p>Second Paragraph</p>
</body>
</html>
The output for the line response.xpath('/html/head/title').extract() returned a list as such:
['<title>Title of the page</title>\n </head>\n <body>\n <h1>H1 Tag</h1>\n <h2>H2 Tag with link</h2>\n <p>First Paragraph</p>\n <p>Second Paragraph</p>\n </body>\n</html>\n'].
It seems like it was able to start from the correct tag but it doesn't stop at the closing tag. Using Visual Studio Code v.1.65.1. Any help would be greatly appreciated.
As you have not provided links or specific HTML that you are trying to parse, it is not possible to reproduce the problem. You do not have a problem in this XPath or this HTML that you posted. See below my results:
In [1]: response.xpath('/html/head/title').extract()
Out[1]: ['<title>Title of the page</title>']
That being said, you have another problem that I am answering here. extract always returns a list, even if there is only one match. The get the first match as string, the method is extract_first.
That's why Scrapy now recommends using get to get the first match as string, and get_all to get the list of strings. See the docs here.
My webpage is rendering each page (~20 pages) with a general wrapper and including it via Thymeleaf (th:include="wrapper :: page"). Im adding ViewControllers for those pages as follows: "registry.addViewController("/").setViewName("index");" (example)
Now my question.. since i want to change the title html tag dynamically for each page..( <meta name="title" th:content="${title}"/>)... is it OK if i change my current addViewController methods for a new Controller, #RequestMapping each page and adding a model model.addAttribute("title", titleVariable);?
Or it would be seen as bad practice to add so many #RequestMapping methods for just changing the html title attribute? is there otherwise another better way of changing the title tag dynamically?
Add this to the page-layout head:
<title layout:title-pattern="$LAYOUT_TITLE - $CONTENT_TITLE">Site name</title>
and it will pull in all titles on your included pages when you have the template setup like this:
<html xmlns:th="http://www.thymeleaf.org" layout:decorate="~{direcory/pagename}">
<head>
<title>This title will appear</title>
</head>
Are you allowed to use jQuery?
$('title').text($('meta[name="title"]')[0].content);
or store it in a variable first
var title = $('meta[name="title"]')[0].content;
$('title').text(title);
Is it legitimate to set the canonical link to the pound symbol as shown below, or am I required to enter a physical page name?
<link rel="canonical" href="#">
When testing this, the pound setting does not generate a validation error (ala #development=1). In my scenario, the page using this layout file will not have an alternate "regular HTML" version. The only version will be the AMP HTML version.
For additional context, I'm experimenting with an MVC site that will use AMP HTML. To keep my layout file simple, I'd prefer to use the pound symbol rather than extracting the child page name and applying that to the href attribute. I know how to apply the URL to the partial view via code like so:
<link rel="canonical" href="#HttpContext.Current.Request.Url.AbsoluteUri">
I'm just curious if it's legitimate AMP HTML to use the pound symbol instead. Thank you.
From the documentation:
Required markup
AMP HTML documents MUST:
contain a <link rel="canonical" href="$SOME_URL" /> tag inside their head that points to the regular HTML version of the AMP HTML
document or to itself if no such HTML version exists.
So instead of using href="#", you should have it point to itself in order to stay consistent with the AMP specifications.
Validation is evolving, the validator doesn't catch all issues today. The issue with using "#" or any relative URL is that when this document is served elsewhere, such as cdn.ampproject.org, that relative URL will no longer point to your intended canonical. You should instead use an absolute URL <link rel=canonical href="URL">.
I would like to know if there is a plugin in order to insert HTML codes in a CKEditor textarea?
I tried to install the PBCKCode plugin but it doens't work because the HTML is executed in my textarea.
Anthony
EDIT1 ----- INSERTPRE Plugin -------
Query when I add the post :
INSERT INTO `Posts` (`slug`,`title`,`thumbnail`,`content`,`tags`,`state`,`click`,`createdAt`,`updatedAt`,`id`) VALUES ('dsq','dsq','http://4.bp.blogspot.com/-knCgLUMOkJc/TeMY2jkmACI/AAAAAAAAAV0/VByHmoMa2N8/s1600/first+blog+posting.jpg','<pre class="prettyprint">\r\n<div>toto</div></pre>\r\n\r\n<p>dqsdqs</p>\r\n','toto','0',0,'2013-04-30 12:15:46','2013-04-30 12:15:46',NULL);
The result in my textarea when I try to edit the post :
<pre class="prettyprint">
</pre>
<div>toto</div>
<p>dqsdqs</p>
As you can see the "div" have changed of place.
EDIT2 ----- Escape HTML -------
Screenshot : http://grab.by/m8bs
As you can see it works in a P tag (just above the slug) but it doesn't work in my textarea. I think CKEditor encode my content but I don't know when and why... In my database everything is ok, I have the codes into the PRE tag.
Check these two plugins:
http://ckeditor.com/addon/insertpre
http://ckeditor.com/addon/syntaxhighlight
We use the first one on http://ckeditor.com/forum and it works very well.
Update: That's because you're not encoding HTML before you pass it to textarea. Use htmlspecialchars (or other similar function if you're not using PHP) to do that.
Update2: You are doing something wrong, but I don't know on what stage. The output data (editor.getData()) from the editor with one <pre> element is:
<pre class="prettyprint"><div></pre>
See that <pre> is not encoded, but <div> inside it is. Your examples show me that you "flattened" that structure - you have encoded both things equally when it should be:
<pre class="prettyprint"><div></pre>
Note: < is an encoded <.
You can use source menu in ck editor header to add your html
Use this tutorial
demo link
Okay Try This
for added Post
addslashes($_POST['post_from_textarea']);
to Edit
stripslashes($yourvairablegetRowsQuery)
I'm trying to change the style of a blog post (for instance change the title color), based on the labels associated to the post.
I'm a bit new to the templating, so I though I would be going to add a class with the label in the title <h3> element, and then add my CSS rules.
So I found this which would generate a proper list of labels separated by a space:
<b:loop values='data:post.labels' var='label'><data:label.name/> </b:loop>
However, it seems the validator does not let me add this inside the class attribute as follow:
<h3 class='post-title entry-title <b:loop values="data:post.labels" var="label"><data:label.name/> </b:loop>'>
From there, I found half the solution. Apparently, I should use expr:class instead of class as follow:
<h3 expr:class='"post-title entry-title " + data:list_of_labels'>
So now:
- How can I build this variable data:list_of_labels? (basically how to set a variable)
- Is there a full description of the template syntax somewhere?
- Is there another way to go around this?
Thanks,
JB
This should do it. Using XML entities allows you bypass the XML validation and move the Blogger functions to where you need them. Longer explanation here: http://www.karlhorky.com/2012/06/add-blogger-labels-to-post-as-css.html
<div class="post<b:if cond="data:post.labels"><b:loop values="data:post.labels" var="label"> <data:label.name></data:label.name></b:loop></b:if>">
<data:post.body>
</div>
There is no way to set variables in the blogger data xml, however you can set variables using javascript.
There are many pages on the blogger data xml. Google is your friend. For example this one.
You are on the right track: do a loop, use javascript to check for the combinations you want, change the style properties or load a css file dynamically.