TYPO3 write name of sys_category into class name at tx_news - typo3

I'using TYPO3 8.7 and write the name of a sys_categoryinto the class name of tx_news-template Item.html, like this:
<div class="{f:format.case(value: '{newsItem.firstCategory.title}', mode: 'lower')}"> ...
Now one of my categories has two words, like 'my category', so the classname results:
<div class="my category">
How can I remove the empty ' ' from class name in FLUID?
Thanks for your help.

Also i would think about using the category uid instead of category name. As names are brittle. An editor might rename somthing and your css code breaks. But your pretty save if you use uids

This is not possible by default - However I see the following options:
1) Create a custom ViewHelper: This would be the best solution as you don't need any 3rd party extension as dependency.
2) Misuse a different field of the category record like seo_title, description or similiar
3) You could use the replace VH of EXT:vhs, see https://fluidtypo3.org/viewhelpers/vhs/master/Format/ReplaceViewHelper.html

You could adjust your css to recognize double classes as well.
.category
.my.category
Still the way to go should be unique identifiers instead of names or titles.

Related

TYPO3 Custom File Name for rendered images

I wanted to ask if in TYPO3 LTS 11 is a way to change how TYPO3 generates the name for a rendered image?
In the template I use the f:image Viewhelper with cropVariant option to generates the image (done by TYPO3 Image Rendering).
<f:image image="{file}" cropVariant="desktop" />
That Image then has a name something like this: csm_my-image_88ade60319.jpg
Can I define how TYPO3 should name those rendered images?
For example to "my-image_large.jpg"
The cms_ part of the filename is hardcoded in the TYPO3\CMS\Core\Resource\Processing\ImageCropScaleMaskTask::getTargetFileName function. The hash at the end is added in the TYPO3\CMS\Core\Resource\Processing\AbstractGraphicalTask::getTargetFileName function. Not sure why cms_ is added, but the hash is to make sure the file name is unique. The hash is generated using the file and configuration.
So by default it isn't possible. If you really want different file names you can XCLASS TYPO3\CMS\Core\Resource\Processing\ImageCropScaleMaskTask with something like:
<?php
namespace Vendor\MyExtension\Resource\Processing;
class ImageCropScaleMaskTask extends \TYPO3\CMS\Core\Resource\Processing\ImageCropScaleMaskTask
{
public function getTargetFileName()
{
$originalFileName = parent::getTargetFilename();
$fancyFileName = ... // Do your things to change the file name
return $fancyFileName;
}
}
You'll probably also want to add something to configure what the file name should be. So you'd probably also need to XCLASS the TYPO3\CMS\Fluid\ViewHelpers\ImageViewHelper class or create a new ViewHelper to add some settings to the processing instructions.
Just make sure the file name is unique or you might get weird results.

Wrap H1-H6 Tags with Typo3 ParseFunc depending on the class set in RTE

I want to add inline-svgs to my h1 to h6 Tags depending on the class set in the RTE.
Example:
RTE:
<h1 class="icon--clock">Header</h1>
Output:
<h1 class="icon--clock"><svg>...</svg>Header</h1>
I've done something similar with links before, using the parseFunc Config. A method like this: https://wiki.typo3.org/External_links
Is there any way to access and split the tag and class like the link parameters through TypoScript?
I also tried using a userFunc
lib.parseFunc.userFunc = ...\MyClass->MyUserFunc
but in Params I only get the tag content, not the tag or the classes that have been set themselves.
I'm using Typo8 with the ckeditor, but I don't think that makes a difference.
Can I even do this?
How do I do this?
I know that I can alternatively add different header layouts and use the tt_content header field, because it's easier to manipulate the template there. But I'd love to know if there is a way to this in the RTE.
I think you could do it in typoscript, but that would be very complicated as you need to analyze the attributes of the Hn-tags.
A simpler method which came to mind would be: use CSS and ::before. So you can use a selector to the class to insert the matching SVG.
This also can be done with javascript but as CSS can do it it would be more efficient to use CSS.

tx_news: extend with a second container $contentElements

TYPO3 8.7.4
news 6.0.0
Is it possible to extend news in a news_extend extension with a second container? (like contentElements)
The goal is to place this second container in the related content of the detail page.
Is there an example?
Yes, it's easy. You need to add field to database, configure it in TCA, extend the news model and adjust the detail template.
in news_extend/ext_tables.sql add:
CREATE TABLE tx_news_domain_model_news (
tx_newsextend_content_elements_second text
);
in news_extend/Configuration/TCA/Overrides/tx_news_domain_model_news.php:
$newNewsColumns = [
'tx_newsextend_content_elements_second' => [
// .... here copy the original 'content_elements' field's config from ext news' TCA. update the label to yours.
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tx_news_domain_model_news', $newNewsColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tx_news_domain_model_news', 'tx_newsextend_content_elements_second', '', 'after:content_elements');
in news_extend/Resources/Private/Language/locallang_db.xlf add:
...
<trans-unit id="tx_news_domain_model_news.tx_newsextend_content_elements_second">
<source>Additional content elements</source>
</trans-unit>
news_extend/Classes/Domain/Model/News.php:
namespace [my vendor]\NewsExtend\Domain\Model;
class News extends \GeorgRinger\News\Domain\Model\News {
// here copy all uses of contentElement field from original model, only name it txNewsextendContentElementsSecond.
// watch whether it's only declared property and getter/setter (simple fields), or something more is done in the model and do it the same way as there.
// tip: see getContentElementIdList() method
}
register your extension as provider of news' model extending class:
in news_extend/ext_localconf.php add:
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['classes']['Domain/Model/News'][] = 'news_extend';
now you can use this in your template:
<f:if condition="{newsItem.txNewsExtendContentElementsSecond}">
<!-- content elements second -->
<f:cObject typoscriptObjectPath="lib.tx_news.contentElementRendering">{newsItem.txNewsExtendContentElementsSecondIdList}</f:cObject>
</f:if>
Above may not just work if you copy-paste it, I'm writing it from my notes. But it will help you to get the idea. Good luck
This should work. Just extend the news tca and model as described in the documentation

Using ViewHelper inside a partial path

I'm working on a new extension and my model has the attribute 'type' which can get different strings from the TCA form. Strings only!
The name of the partial that my template should load is inside the 'type' attribute from my model. So here comes my problem. Since TYPO3 4.7.x the .html file names for fluid have to start with an uppercase letter. Inside the 'type' attribute the name of the partial that should be loaded is always lowercase. For that, I wrote a simple view helper that contains only this method:
public function render($string) {
return ucfirst($string);
}
Inside my template I tried to use this view helper for the path to the partial:
{namespace vh=Tx_MyExtension_ViewHelpers}
<f:for each="{obj.subObjects}" as="sub">
<f:render partial="OtherObject/{vh:String.UpperFirstCharacter(string:'{sub.type}')}" arguments="{sub:sub}" />
</f:for>
If I try to load this in the fontend, nothing from my extension will be rendered and there are no error messages anywhere. The problem depends on my view helper, 'cause even if I try to load only this:
{vh:String.UpperFirstCharacter(string:'test')}
{vh:String.UpperFirstCharacter(string:'{sub.type}')}
There is nothing comming back. If I only output {sub.type} it shows me the string that I want, but in lowercase.
Obviously your problem is that you're ViewHelper doesn't do what you want it to do.
First of all, ViewHelper names are to be written in lowerCamelCase.
Second, you don't need to place sub.type in curly braces:
This syntax...
{vh:string.upperFirstCharacter(string:sub.type)}
... should be sufficient.
Fluid will then look for a ViewHelper named
Tx_MyExtension_ViewHelpers_String_UpperFirstCharacter
or namespaced
\My\Extension\ViewHelpers\String\UpperFirstCharacter
Please check that this is the case.
So I found the issue. Fluid can't handle namespaces. So first my ViewHelper looked like this:
<php
namespace TYPO3\MyExtension\ViewHelpers\String;
class UpperFirstCharacterViewHelper ...
Now I changed the name of my class and removed the namespace:
<php
class Tx_MyExtension_ViewHelpers_String_UpperFirstCharacterViewHelper ...
This is how it works. At the moment I work with TYPO3 6.1.6.
Thank you anyway lorenz for your help!
EDIT:
I went fully retarded! Fluid CAN handle namespaces. I just had to set the namespace the right way.
That's how you set the namespace inside the template:
{namespace vh=TYPO3\MyExtension\ViewHelpers}
On top of this comment you can see how my ViewHelper looks like with a namespace.

Silverstripe FulltextSearchable add custom fields

I need a custom field to be FulltextSearchable. Therefore I tried this code as described in the FulltextSearchable class:
Object::add_extension('Page', "FulltextSearchable('SearchableContent')");
then run dev/build.
Basically Fulltext Search seems to work. But the content of the custom Field 'SearchableContent' seems never to be checked.
Of course I enabled FulltextSearch first by:
FulltextSearchable::enable();
Thx,
Florian
All SiteTree classes have their search columns define in FulltextSearchable like:
$defaultColumns = array(
'SiteTree' => '"Title","MenuTitle","Content","MetaTitle","MetaDescription","MetaKeywords"',
'File' => '"Title","Filename","Content"'
);
so I don't think SilverStripe will pick up on your extra column. Unless you edit the FulltextSearchable but that's probably a bad idea... or just create a custom search function like for plain DataObject so you can specify exactly which columns to search on:
silverstripe dataobject searchable