So I'm trying to render a page's URL in the head of the document, for use with rel=canonical. This is on a site running off Velocity templates. The type of content I'm talking about is specifically a quiz -- which has multiple pages, one for each question, not to mention different URL paramters reflecting how many answers the user has gotten correct.
The site has redirect rules in place to generate the URL for the quiz. They look like this:
<rule>
<from>^/([a-zA-Z_0-9\-]*)/(quiz_[a-zA-Z_0-9\-]*)/(\d*).htm$</from>
<to>/contentdata/quiz.htm?path=/$1/$2.xml&qnum=$3</to>
</rule>
All this is by way of explaining that I'm using this Velocity code:
<link rel="canonical" href="$link.self" />
On the template for this page:
http://example.com/fun/quiz_best_quiz_ever/1.htm
Which produces this HTML:
<link rel="canonical" href="/contentdata/quiz.htm" />
But what I want is this HTML:
<link rel="canonical" href="http://example.com/fun/quiz_best_quiz_ever/" />
Is that clear enough? I know this is complicated, but does anyone have any idea as to how I may be able to accomplish it?
Your Velocity template needs to know what the rest of the URL is. You didn't explain how you are rendering the Velocity. Is it Spring? Velocity Servlet? Some other system?
The basic idea is that you need another reference called $baseUrl. Set this in your java code before the Velocity template is merged
(in Java)
context.put("baseUrl", "http://example.com/fun/quiz_best_quiz_ever");
(in Velocity)
<link rel="canonical" href="$baseUrl/$link.self" />
Related
currently am working in a Golang Site, as frontend I am using the go templates. In order to separate the different parts of the sites I created this templates:
Head: containing the <head> tag, and some imports of css
Header: defining the navbar of the site, logo, etc. It's only HTML
Footer: defining the HTML of the footer of the site.
SomePage: defining the body tag, this template calls Head, Header and footer. This file can be for example the index, the login, etc.
I added the Javascript imports just after I nest the footer template, but still inside the body tag. As example, I added them like:
<script src="public/js/SomeJS.js"></script>
<link href="public/css/SomeCSS.css" type="text/css" rel="stylesheet"/>
In the routes of my project I have defined public to serve those static files, this is working pretty nice. Now, I have some routes of the project, lets say:
router.GET("/",controllers.Index)
router.GET("/login",controllers.Login)
With the first route, the libraries are being loaded pretty well. Then, with routes as the second, I am not able to load them because the browser tries to locate that files as:
http://myserver/login/public/css/someCSS.css instead of
http://myserver/public/css/someCSS.css
In this case, I understand why it's adding the login to the URL. So, my question is, how it's normally handled?
By now I added the domain and folder to the imports, example:
<script src="MyDomain.com/public/js/SomeJS.js"></script>
But I really don't want to do it in this way, because anytime that the domain change I should be editing the code and it's not really pratical. Also, I don't want to add the imports of the libraries in every view that I create. I have some files (CSS and JS) that are common for all the project and I just want writte it once.
Thank you!
Add / in the being of the path, it is called relative path from domain root.
<script src="/public/js/SomeJS.js"></script>
<link href="/public/css/SomeCSS.css" type="text/css" rel="stylesheet"/>
Without /, it is called as relative path from current domain directory. This is the behavior you have right now.
Output:
http://myserver/public/css/someCSS.css
http://myserver/public/js/SomeJS.js
What is the best way to incorporate css / js assets into Odoo's website where the assets are only loaded for a particular page?
In the examples and documentation they speak of dumping your assets into Odoo's website.assets_frontend and I do this however there are circumstances where I would like to use website templates found online and I really do not want to take the time to look through the css classes and identify conflicts.
If the page itself were to fail that is one thing but if it breaks all the css on my existing pages that is another.
I was thinking of using a technique like this.
t-if="request.httprequest.path.startswith('/page/path/')"
Using an if statement to determine whether or not to incorporate the css in the website assets or not.
<odoo>
<data>
<template id="page_style" name="Page Style" inherit_id="website.assets_frontend">
<xpath expr="link[last()]" position="after">
<t t-if="request.httprequest.path.startswith('/page/path/')">
<link href="/addon_name/path/to/css/style.css" rel="stylesheet" type="text/css"/>
</t>
</xpath>
</template>
</data>
</odoo>
Anyways, if anyone would like to make a suggestion on how they incorporate css into Odoo's frontend assets in a contained way I would appreciate it.
What you can do is actually insert a:
<head>
<link href="/addon_name/path/to/css/style.css" rel="stylesheet" type="text/css"/>
</head>
to your template that you want the specific css/js to be applied to. For a specific example see addons/website_google_map/views/google_map_templates.xml
Your the contents of your head tag will be inserted inside the head tag of the final HTML that will be rendered for that template.
Since it seems to be straighforward and used by the framework itself I have resorted on using it on my own with no problems so far. As I can understand you can also create a javascript Widget that will operate on your template only that will apply a specific css. But the above solution seems cleaner to me.
I want to know if it is possible to let apache substitue a link in the html I return to the client with the html of the site behind the link.
So instead of
<html>
<head>
</head>
<body>
Link
</body>
</html>
I want something like this:
<html>
<head>
</head>
<body>
// the html of the page behind the link
</body>
</html>
I can´t use javascript or php or anything, let´s assume I only have html.IFrames are as well no solution for my problem.
Just for everyone that comes to a similar situation, Ulrich Schwarz gave a good hint with SSIs, which is in this scenario the only way that could work. However, due to cancelling the project, I was not able to validate the usage of SSI for this scenario.
This can be little painful to do and might not be suitable for all cases but you can maintain a plaintext file for every html page you want to show source of and add a link to that file instead.
For eg: Instead of <a href='somefile.html'>Click</> do <a href='somefile.source'>Click</>
where somefile.source is the copy of the somefile.html. Add triple qoutes """ in the first and the last line of the file. I didn't try a lot of combinations but this works for fairly decent html codes.
I am struggling to understand the scope of resources defined with the Grails resources plugin.
I have created a small project (Grails 2.0.4) with a single domain item of Book and generated the associated Controller and Views.
I have then modified the main layout as follows:
<html>
<head>
<g:layoutTitle/>
<r:layoutResources/>
</head>
<body>
<g:layoutBody/>
<r:layoutResources/>
</body>
</html>
When I run the app I get no styling as expected.
I now add the following to the head list.gsp
<head>
<meta name="layout" content="main"/>
<r:require modules="jquery-mobile"/>
</head>
When I go to the list page now I correctly get the jquery-mobile styling as expected but when I go to the create page I also get jquery-mobile styling but was expecting no styling, as this page does not contain the tag.
It seems that the resources selected for one page are being used for all other pages. Is this expected behaviour?
Thanks,
Kim
Use Resources 1.2, it sounds like this might be an old bug.
I am working on some search engine optimisation for my expression engine site. I need to add some link tags into my head to allow google crawlers to acknowledge the relationship between paginated pages in my blog.
I need to add:
<link rel="next" href="http://www.mysite.com/news/latest-news/P10" />
to the first news page, then:
<link rel="prev" href="http://www.mysite.com/news/latest-news/" />
<link rel="next" href="http://www.mysite.com/news/latest-news/P20" />
to the next page, and some on until the final page where I'll add
<link rel="prev" href="http://www.mysite.com/news/latest-news/PXX" />
I have been trying to achieve this by using the following code:
First news page:
{if last_segment == "latest-news"}
<link rel="next" href="http://www.6dg.co.uk/news/latest-news/P10" />
{/if}
This works fine, but for subsequent pages I have tried this, which does not work as PX is not accessible as a url segment.
{if last_segment == "P10"}
<link rel="prev" href="http://www.6dg.co.uk/news/latest-news" />
<link rel="next" href="http://www.6dg.co.uk/news/latest-news/P20" />
{/if}
{last_segment} returns latest-news.
Does anyone know how I can get round this issue?
I also have another issue with this method. Currently I only have 3 paginated pages, but this will go up as more entries are added, so I am not going to know what segment value to target in order to add my final link tag.
Any help will be greatly appreciated.
I am using expressionengine version 2.2.2
This is actually a really tricky question. There's no native way to accomplish this in EE, so you'd have to write a custom add-on to do this properly.
You might want to delete this and instead post it over on the new ExpressionEngine StackExchange, where you'll have more capable eyes on it.