TYPO3: getting relative URLS with "/" in the beginning - typo3

There is an extension in my TYPO3 website that uses the following line of Typoscript:
EXT:ts_example/social_bookmarks-min.js
This translates to
typo3conf/ext/ts_example/social_bookmarks-min.js?1416308825
If I use absolute URLs in my website, this is not a problem, but if I intend to use relative URLs, this won't work, as it won't replace the entire pathname of the base URL, since it does not start with "/".
In short, I wish that it would output this instead:
/typo3conf/ext/ts_example/social_bookmarks-min.js?1416308825
Is there a way to achieve this?

In your main TypoScript use:
config.absRefPrefix = /
and DON't use config.baseURL at the same time!

Related

XML Sitemap with typoscript makes wrong URLs

According to http://www.typo3-probleme.de/2018/07/11/typo3-sitemap-mit-typoscript-erstellen-2285/ I let TYPO3 V8.7.24 generate the sitemap.xml file. So far it works. But in the file there are not proper URL's. On every URLs end is "?type=500001", for example an URL looks like "https://www.domain.ch/angebot/online-marketing/?type=500001". As a side note , there is also Ext:Realurl in use.
My request is, how can you remove the segment "?type=500001" ? Is the reason typoscript or the extension Realurl? How can I analyse it?
Any hint is welcome. Thanks in advance for your help.
It's the link generation inside of TYPO3. that is configured by typoscript, so you could see typoscript as the culprit.
If you want to know whether realurl (or any other extension) is the culprit: disable the extension in mind. if the error is gone there is a reason to suspect this extension.
When links are generated by TYPO3 it holds some parameter to stay in the current context. Which paramaters should be considered is a configuration (so it is grounded in typoscript).
Have a look (TSOB) at config.linkVars in general (it is copied implicit to every page object) or of your page object page.config.linkVars (in your case: xml_sitemap.config.linkVars)
There is a note in the manual:
Do not include the type parameter in the linkVars list, as this can result in unexpected behavior.
Other option would be to explicit set &type=0 to every link. But don't forget to set config.uniqueLinkVars = 1 (or xml_sitemap.config.uniqueLinkVars = 1)

EJS Static css files stop working when i pass reference parameter in URL

I am using ejs template engine and express js (node js), when i pass the reference parameter in url, static css files stops work
Your reference parameter is separated from the rest of the URL by a path separator character (/).
Relative URLs which don't start with a / are relative to the current path.
By changing the path, you change where the URL is relative to.
Since you are relative to a different path, your new URL resolves to the wrong place.
Change the href of your link to the stylesheet so it points to where the stylesheet is. This is most easily achieved by starting it with / (e.g. href="/static/styles/your.css").

Get path of FAL media?

Using Fluid Template with tx_news, I need to get the URL of uploaded FAL video.
Currently I have this:
{newsItem.falMedia.0}
Which prints:
GeorgRinger\News\Domain\Model\FileReference:3
I want the output:
fileadmin/user_upload/MyVideo.mp4
newsItem.falMedia seems to be an ObjectStorage. With .0 you are pointing to the first object of it - not any function of it. In the API you can see its functions http://api.typo3.org/typo3cms/current/html/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_resource_1_1_file_reference.html or you can debug it in Fluid by using {newsItem.falMedia.0}
Example: {newsItem.falMedia.0.publicUrl} should give you the public path to the file.
If you just need url of image than use following line
{object.image.originalResource.publicUrl}..
TYPO3: get path out of file reference in Extbase
Please refer above link.

In a fluid template, how to output the linked file's size?

In a fluid template, I would like to output a linked file's size.
I'm using f:link.page to link to the file, as I think this is the way to do it (please correct if not).
<f:link.page class="download" pageUid="fileadmin/redaktion/download/papers/{paper.download}" {paper.author}">PDF</f:link.page>
As I'm already using the extension ml_links on the site, I thought I could pass the link through lib.parseFunc_RTE, but
<f:format.html parseFuncTSPath="lib.parseFunc_RTE"><f:link.page class="download" pageUid="fileadmin/redaktion/download/papers/{paper.download}" {paper.author}">PDF</f:link.page></f:format.html>
just wraps it into p.bodytext.
Do I have to use a different syntax to apply f:format.html TO f:link.page - or is there a better way to do it (via a fluid or vhs viewhelper)?
Actually custom VH is fastest way to achieve that, i.e. basing on this VH, you'll need to replace size param with a file path, and then use i.e. filesize function of PHP to fetch the size in bytes.
Here's my VH:
https://gist.github.com/ursbraem/9645542
I've simplified the original a little, outputting "KiB" for file size is too technical for me.
The easiest way is to use native TYPO3 FAL parameter originalFile.size :
{audio.0.originalFile.size -> f:format.bytes()}
When i use fluidcontent i have vhs extension installed aswell and then just use:
<f:format.bytes decimals="1">{v:media.size(path: '{file}')}</f:format.bytes>
This outputs clean readable sizes like "28.2 MB".
If you are using VHS you may consider https://fluidtypo3.org/viewhelpers/vhs/master/Media/SizeViewHelper.html (in combination with f:format.bytes).
In newer TYPO3 versions you can use the originalResource.size attribute of a FileReference object.
{file.originalResource.size -> f:format.bytes()}
or in your case:
{paper.download.originalResource.size -> f:format.bytes()}
TYPO3 10
I needed a file size output for a DCE module in TYPO3 10, this is what I came up with, using VHS:
<f:format.bytes><v:media.size><v:format.trim characters="/"><f:uri.typolink parameter="{item.link}" /></v:format.trim></v:media.size></f:format.bytes>
Explained:
f:uri.typolink generates the full path I need for v:media.size
v:media.size requires the path without a leading slash, v:format.trim removes this character.
f:format.bytes displays the output from v:media.size in KB or MB.

create menu with baseURL in front of link (absolute links)

When I create my menu I only have relative paths for the different menu links. How do I get an absolute URL (i.e. a typolink with the baseURL in front of it).
I can think of either defining a variable or write the domain name in the wrap. E.g.
10.wrap = <option value="http://www.domain.com/|">
But are there better options?
Simply set the typolink parameter forceAbsoluteUrl of the links in your HMENU construct: http://wiki.typo3.org/TSref/typolink
Set config.absRefPrefix = http://www.yourdomain.com/sub/path/. That will prefix any properly generated site-root relative links with the domain.
There may be an alternative way using domain records (Linking across domains in multidomain-sites does exactly what you want), but I can't point you to anything there.