TYPO3 Custom File Name for rendered images - typo3

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.

Related

How to access data from FLUIDTEMPLATE file and render that content in our desired file?

I have my package from sitepackagebuilder (v9.5.14). I no good at Typoscript. I am using the optional menu navigation file MainBefore.html (my desired file) from bootstrap_package which I put in my stpkg extension because this file is globally available in the FE alongside main menu. I try to explain my doubt in the two following examples.
First one is clear to me. usually I do things like this, (My only known typoscript way to access and render things).
Example 1:
In typoscript
lib.stdContent = FLUIDTEMPLATE
lib.stdContent {
file = EXT:sitepackagebuilder/Resources/Private/Partials/Page/DropIn/Navigation/Data.html
variables {
mylabel = TEXT
mylabel.value = Label coming from TypoScript!
}
}
In Data.html
<h4>Hello TYPO3</h4>
<h3 hidden>{mylabel}</h3>
MainBefore.html
....
<div class="from-data-file"><f:cObject typoscriptObjectPath="lib.stdContent" /></div>
....
The above example will work.
Example 2:
But this following example is my doubt.
page.10 = FLUIDTEMPLATE
page.10.variables.userInfoForChat = COA_INT
page.10.variables.userInfoForChat {
10 = FLUIDTEMPLATE
10 {
file = EXT:company/Resources/Private/Partials/Page/DropIn/Navigation/Data.html
variables {
mylabel = TEXT
mylabel.value = Label coming from TypoScript!
}
}
}
How can I access variables in Data.html and render content in MainBefore.html like example 1? Correct me If I am wrong
Both files are in same location.
First: you are doing very complicated things. normaly stacking templates inside each other is not necessary. so the main question would be: What do you intend to do?
Then we can find a simple way to do it.
I try to identify your intention:
you have a main template (main = main for this example, otherwise it is just a small part of the general page rendering) where you want to have a variable, which is filled from another template, where some variable is inserted.
Some information is missing as these would not be necessary when all values are static like in your example.
There must be something non static as you use a uncached COA_INT and the name userInfoForChat hints to something user specific, which of course is not cachable.
My question is: why do you put a complete fluid templating in the variable, when it should be enough to have only some uncached values in it and stay with just one set of fluid template. (That set already could consists of template, layout and a lot of partials)

Custom tags in TYPO3 content

new here, and also new to TYPO3.
I need to put something like [imagebox, title='box1'] into content editor and that will be replaced by a text and image with some javascript effect (text and image are managed in the DB elsewhere, the tag is just for the placement in the page).
I've read that TYPO3 has a mechanism for adding custom tags and I managed to make them accepted in the RTE.
I tried instead of [imagebox..... to use
<imagebox>box1</imagebox>
with something like this (copied from web):
tt_content.text.20.parseFunc.tags {
imagebox < lib.parseFunc.tags.link
imagebox = TEXT
imagebox.value= replaced
# imagebox = PHP_SCRIPT
# imagebox {
# stripNL = 0
# Pass a parameter from Typoscript to a PHP script:
# UID of the page containing the SINGLE view of tt_news
# id_singleView = 18
# Call the PHP script
# file = fileadmin/scripts/imagebox_parser.php
# }
}
lib.parseFunc.tags.imagebox < tt_content.text.20.parseFunc.tags.imagebox
should be able to replace content between tags.
I've commented call to php function just tried to get a text replacement for starters.
I've put that in the main root template Setup, but nothing is replaced.
I've also tried other examples from the web with no success.
Did anyone have situation like this?
Are there better approaches for that in TYPO3? (I'm using v7.6.23)
Any suggestion or hint is appreciated.
EDIT: using FSC on textmedia element
I think your examples are outdated. (the object PHP_SCRIPT is obsolete for a long time)
You might have a look at the documentation for your TYPO3 version:
https://docs.typo3.org/typo3cms/TyposcriptReference/7.6/Functions/Parsefunc/
you also need to enhance the parsefunc where you need it. That can depend on:
CSC or FSC?
which kind of content element (CE) do you use? (be sure to enhance the rendering of that CE)

Order of Constants TS in Template Analyzer

i'm struggeling with the order of typoscript in constants. I've a provider extension holding all the templates and files for the site. Typoscript ist used in external files, i don't want to store typoscript in the database. I use typo3_forum ext and want to modify the templates to customize it. But when i put the ts for the view like:
plugin.tx_typo3forum {
view {
templateRootPath = EXT:provider/Resources/Private/Templates/Forum/Standard/
partialRootPath = EXT:provider/Resources/Private/Partials/Forum/Standard/
layoutRootPath = EXT:provider/Resources/Private/Layouts/Forum/Standard/
}
}
these values will be overwritten by the typo3_forum ext itself, cause the constants of typo3_forum ext stands in the templateAnalyser hirachy under my provider extension.
Sure storing the above ts in the constants field of my roottemplate solves the problem but is there no solution for external fiels to sort?
I've tried:
plugin.tx_typo3forum.view.templateRootPaths.100 = EXT:provider/Resources/Private/Templates/Forum/Standard/
but this doens't work, the ext uses the default template in that case.
Thanks for your help!
Cheers Mark
Put your line
plugin.tx_typo3forum.view.templateRootPaths.100 = EXT:provider/Resources/Private/Templates/Forum/Standard/
in the setup, not in constants.
You can move the path to constants like
Constants:
plugin.tx_typo3forum.view.myTemplateRootPath = EXT:provider/Resources/Private/Templates/Forum/Standard/
Setup:
plugin.tx_typo3forum.view.templateRootPaths.100 = {$plugin.tx_typo3forum.view.myTemplateRootPath}
If using TYPO3 version 8, take a look at https://forge.typo3.org/issues/75862. There is a bug regarding the fallback for template paths. The issue has been solved already and is targeted for version 8.4
The order of TS appearing in the template analyser simply reflects the order in which the files are loaded.
If you are already using a provider extension for your TypoScript and don't put any TS statements in the database (which is a good practice) you can go one step further and put no extension TS in the database at all (not even include static templates in the template record).
Just include the TypoScript files that you need in your provider extension with <INCLUDE_TYPOSCRIPT and you have complete control of the order of things.
In the database you have to put just one line in constants and one in setup, each of the including from your provider extension. This will also make you less dependent of the database because if you include a new file it is just loaded and no actions are needed in the actual template record in the backend.

Why can't I access my extensions' settings on the frontend?

Trying to access a few settings that I've created in my constants.txt file. It looks like this:
plugin.tx_my_ext {
settings {
# cat=plugin.tx_my_ext/urgences; type=boolean; label=Activer les urgences
activerUrgences = 0
}
}
Then in my setup.txt file I have this:
plugin.tx_my_ext.settings.activerUrgences = {$plugin.tx_my_ext.settings.activerUrgences}
Any reason why I wouldn't be able to access my settings using {settings} in my Fluid layout?
BTW, my extension name does include an underscore _ between the words. I have tried removing the underscore, then removing the tx_, and then a combination of those two.
Any help would be appreciated!
Thanks
For ext with key my_ext it should be plugin.tx_myext.settings
Make sure that you 'Included static from extension' in your TypoScript Template. If your ext is not available on the list add it in ext_localconf.php like that:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'MyExt');
Do not forget to clear System cache and FE cache at least million times ;)
Use TypoScript object browser to check if on given page your plugins TS is still available (maybe something resets TS in meanwhile:
Finally make sure that you don't clear $this->settings array within your controller, if you do manipulate it for any reason assign it to the view again before view rendering,like that:
$this->view->assign('settings', $this->settings);

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.