Fluid Viewhelper f:format.json returns htmlentities and more problems with curly braces in fluid - typo3

in TYPO3 8 LTS i try build a json output from news list. When using the viewhelper f:format.json in exact the same way as in the fluid manual:
{f:format.json(value: {foo: 'bar', bar: 'baz'})}
i get this:
{"foo":"bar","bar":"baz"}
this works:
{f:format.json(value: newsItem.datetime)->f:format.htmlentitiesDecode()}
but i need the date-object formatted in this way:
{newsItem.datetime->f:format.date(format: "%Y-%m-%d")}
and now i am looking for a possibility to match both in order to get this output:
{'date':'2018-03-16'}
I tried a many ways like this, but nothing works.
{f:format.json(value: {date:newsItem.datetime->f:format.date(format: "%Y-%m-%d")})->f:format.htmlentitiesDecode()}
any idea how to get it right?
Thanks
Peter

well Bernd showed me the way in his comment above - here is one of the solutions which i found with this little help of him:
{f:format.json(value: {date:'{newsItem.datetime->f:format.date(format: "%Y-%m-%d")}'})->f:format.htmlentitiesDecode()}
f:format.raw works much the same like f:format.htmlentitiesDecode; really important are the two '' around {newsItem.datetime->f:format.date(format: "%Y-%m-%d")}.
With the idea of format.raw i found an other solution too:
<f:format.raw value='{"date":"' />{newsItem.datetime->f:format.date(format: "%Y-%m-%d")}<f:format.raw value='"},' />
Looks quite a bit complicated but with
<f:format.raw value='{' />
<f:format.raw value='}' />
it is possible to use curly brackets in fluid templates.
Thanks!

Related

Empty cell Typo3 Fluid

Trying to set up a query for the "address list-Plugin" in Typo3.
So if my cell "Title" is written to there would be some information like "Prof.Dr." but if there's no Title on the Entry there should be "-"
Got no code at all at this point because its totally new to me but i assume it would like this a bit:
f:if condition{empty.cell} - or something. Never worked with it till yesterday and can't find any documentation that's helpful about my problem
An introduction to FLUID could be found here
A special hint for beginners:
If you want to know which FLUID variables are defined you can use of the f:debug Viewhelper:
<f:debug title="info at ...">{_all}</f:debug>
The exact syntax for your usage would be:
<f:if condition="{address.title}">
<f:then>{address.title}</f:then>
<f:else>-</f:else>
</f:if>

Link to file in Fluid – how to specify storage?

As far as I know, there's no such thing as an f:link.file or v:link.file viewhelper.
There used to be a solution using file.originalResource.publicUrl as the value to point the link to, as in
<f:link.page pageUid="{file.originalResource.publicUrl}" target="_blank">
Am I right that this is no longer necessary? I got this (using ext:mask):
<f:link.page pageUid="{file.identifier}" target="_blank">
returning the same value, while originalResource.publicUrl would not even show up in f:debug.
BUT in file.identifier the storage path, e.g. fileadmin, is not present. How do I add it to the viewhelper?
Or, what is the currently recommended solution for a link to a file in TYPO3 7.6?
Just use {file.name}. When absolute URL or some special configuration is needed use <f:link.typolink parameter="{file.publicUrl}">{file.name}</f:link.typolink>.
TYPO3 11 introduced a new ViewHelper for this
<f:link.file file="{file}" target="_blank">Download</f:link.file>
https://docs.typo3.org/other/typo3/view-helper-reference/11.5/en-us/typo3/fluid/latest/Link/File.html
For me, #minifranske’s solution worked only as a hint: I needed to use {file.originalResource.publicUrl} instead:
<f:link.typolink parameter="{file.originalResource.publicUrl}">{file.originalResource.title}</f:link.typolink>
also available:
{file.originalResource.name}
{file.originalResource.description}
{file.originalResource.alternative}
Nevertheless, if anybody knows a proper core solution which resembles that of the Rich Text Editor, I’d be happy to hear about it:
file link
page link
<f:uri.image image="{imageObject}" /> produces the path + filename for your FAL object.

Naming sections with docco/markdown?

Using CoffeeScript and Docco, sections are created in the generated HTML which can then be used as links eg.
geometry.html#section-82
Does anyone know if there is a way to name these sections so it could instead be (for example):
geometry.html#vector
EDIT: It would seem this can be achieved by simply adding in the HTML manually:
**MARKDOWN**
# ## <section id='vector'>Vector:</section>
but is there any other, perhaps more elegant ways?
Currently the best way I can find to do this is as follows:
# ## <section id='vector'>Vector:</section>
It seems to work pretty well, wish I could add it to Markdown though.

Convert links in blockquotes to plain text

So, I've been asking a lot of Xpath questions recently.
Sorry, but I've only just started using it, and I'm working on a kind of hard project.
You see, at the moment I'm parsing HTML like this (not a copy and paste, just an example):
<span id="no153434"></span>
<blockquote>Text here.<br/>More text.<br/>Some more text.</blockquote>
And I'm using
//span[starts-with(#id, 'no')]/following::*[1][name()='blockquote']//node()
To get the text inside.
It's working fine, although it's very frustrating. I need to manually check for then manually combine the strings before and after the br, add a newline, and so on. But it stills works. Until there is a link in the text, that is. Then the code is like this:
<span id="no153434"></span>
<blockquote>Text here.<br/>Text.<br/><font class = "unkfunc">linkhere</font></blockquote>
I have absolutely NO idea where to go from here, as the link is included as a completely seperate item (twice) in the array. Atleast with the br I knew where it had to be moved to. Really contemplating giving up in this project after all this effort.
You can use this XPath to obtain text inside element: //span[starts-with(#id, 'no')]/following::*[1][name()='blockquote']//text()
So you receive following result:
Text here.
Text.
linkhere
If you want only text nodes and br:
//span
[starts-with(#id, 'no')]/
following::*[1][name()='blockquote']
//node()
[ count(.|..//text()) = count(..//text())
or
name()='br'
]
returns
Text here.
<br />
Text.
<br />
linkhere
The answer is to not use XPath for this kind of work.
Got it working 1,000,000x easier with Objective-C-HTML-Parser.

Zend Framework Filter Input StripTags and "<3"

I'm currently using Zend_Filter_StripTags in a commenting system, but stuff kinda breaks when '<3' is entered. StripTags doesn't seem to be smart enough to realize that it's not an HTML tag, and creating the filter as "new Zend_Filter_StripTags(array('3'))" doesn't seem to work either.
Should I pass the input through a regexp first, or is there a way to get Zend_Filter_StripTags to straighten up and fly right?
Ended up writing a Zend_Filter class that was basically a wrapper for HTMLPurifier. Works perfectly, because HTMLPurifier is a LOT smarter than striptags.
I'm not familiar with Zend much, but if you want stuff like <3 to be allowed, just do htmlspecialchars instead of strip_tags on it.
What you want is Zend_Filter_HtmlEntites most likely.
See: Zend_Filter_HtmlEnties
The problem with htmlspecialchars and Zend_Filter_HtmlEntities is that if you're trying to strip out all html tags ( like 'a' and 'img', etc ), then instead of stripping them, you end up with that markup in your output.
Take comments on a blog for example. If you use htmlspecialchars or Zend_Filter_HtmlEntities, in a comment where someone tries to use html to enter a link you end up with that markup showing up when you display the comment. But if you use strip_tags or Zend_Filter_StripTags you end up mangling the comment, as neither is smart enough to realize that '<3' isn't a tag, and just strips everything from '<3' until the end of the comment ( or until it finds '>' ).
It would be nice if Zend had something like HTMLPurifier, where it actually checks and validates the input before stripping tags. This means that stuff like '<3' gets left alone, where as stuff like 'Awesome Site' becomes 'Awesome Site'.
This is a problem I'm trying to work around, and at the moment it seems like I'm going to end up writing my own Zend_Filter class that's basically a wrapper for HTMLPurifier.