Read DB entries dynamically in TypoScript - html

I have the following setup for my Typo3 installation:
TypoScript:
lib.responsiveImage = IMAGE
lib.responsiveImage {
default = IMAGE
default{
file {
import.current = 1
treatIdAsReference = 1
}
altText.data = DB:sys_file_reference:26:alternative
titleText.data = current
}
}
Which produces the following output Tag (unneccessary content deleted; important is the alt and the title tag):
<img class="img-responsive" srcset="XY.jpg" alt="AltText" title="26" sizes="(min-width: 1200px) 1100px">
As you can see, current delivers the correct uid of "26". The database query via DB:sys_file_reference:26:alternative delivers the correct "AltText".
However -> How could i achieve that dynamically?
I tried something like this
DB:sys_file_reference:{current}:alternative
but this doesnt worked. current should be the uid of an FileReference
(Also altText.data = file:current:alternative gives me an Error: No File Object)

Maybe the use of the FILES element is safer:
lib.responsiveImage = FILES
lib.repsonsiveImage {
references.current = 1
renderObj = IMAGE
renderObj {
file.import.data = file:current:uid
file.treatIdAsReference = 1
altText.data = file:current:alternative
titleText.data = file:current:title
emptyTitleHandling = useAlt
}
}

Luckily i found a solution:
default = IMAGE
default{
file {
import.current = 1
treatIdAsReference = 1
}
sourceCollection < tt_content.image.20.1.sourceCollection
layout < tt_content.image.20.1.layout
layoutKey = srcset
altText.data.dataWrap = DB:sys_file_reference:{current}:alternative
altText.wrap = |
}
If you use dataWrap the {current}works as expected!

Related

Reading TYPOscript fe_users does not work within a COA

I have just the following problem, I would like to spend via TYPOScript a specific FE_user in the template, only this does not work, is there a restiktives SQL statement or I use here what wrong? Maybe it's the nesting?
Here is the code:
lib.contactPasswords = COA
lib.contactPasswords.10 = TEXT
lib.contactPasswords.10.value (
<p>User: Safari</p>
)
lib.contactPasswords.20 = CONTENT
lib.contactPasswords.20 {
table = fe_users
select {
max = 1
pidInList = 173
andWhere = username = 'Safari'
}
renderObj = COA
renderObj
{
10 = TEXT
10.field = username
wrap =|<br / >
}
}
lib.contactPasswords.20.wrap = <div>User: |</div>
And the output is the same like:
<p>User: Safari</p>
<div>User:</div>
Desired result:
<p>User: Safari</p>
<div>User: Safari</div>
Can someone explain to me where the mistake is, why the content remains empty?
More Information:
TYPO3 Version: 8.7.19
Using like: <f:cObject typoscriptObjectPath="lib.contactPasswords" /> in Fluid Template
And yes: The User "Safari" exist in the database :)
Are you sure the username is Safari? Usernames are usually all lowercase in TYPO3. If you added it through the backend it will be cast to lowercase. So it would be safari.
You should not have an enter between cObject and {. It should be cObject {
Also andWhere is deprecated since TYPO3 7.1 and removed in TYPO3 8.7. You should use where instead.
For me, this works:
lib.contactPasswords.20 = CONTENT
lib.contactPasswords.20 {
table = fe_users
select {
max = 1
pidInList = 173
where = username = 'safari'
}
renderObj = COA
renderObj {
10 = TEXT
10.field = username
wrap = |<br / >
}
}
'andWhere' reqires, that you also used 'where' in your statement.
But avoid using 'andWhere' since it is deprecated. See https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.1/Deprecation-25112-andWhere.html

TYPO3 7.6: bodytext html output with typoscript?

After I upgraded TYPO3 from 6.2.9 to 7.6.15 the bodytextfield isn't parsed as HTML anymore. My typoscript creates XML output and I need the bodytext as HTML output.
...
10 = CONTENT
10 {
table = tt_content
select {
where = colPos=0
orderBy = sorting
selectFields = image,header,bodytext
languageField = sys_language_uid
}
wrap = <items>|</items>
renderObj = COA
renderObj {
wrap = <item>|</item>
10 = TEXT
10 {
wrap = <title>|</title>
field=header
}
20 = TEXT
20 {
wrap = <text><![CDATA[ | ]]></text>
field = bodytext
parseFunc = < lib.parseFunc_RTE
}
...
I think the lib.parseFunc_RTE is not working anymore?
Using =< you are referencing to lib.parseFunc_RTE. If it gets deleted somewhere in your Typoscript, the reference will be lost. Check out the Template -> Typoscript if lib.parseFunc_RTE is still present in your Typoscript.
You also can try to not reference it by just copying it
parseFunc < lib.parseFunc_RTE

Adding of Generic Markers to tt_news - Database related

I am trying to write a custom output to extend the tt_news-Extension. I have suceeded so far as I have successfully written:
My own extension (via the help of extension builder)
Found a method to output some of my data via GENERIC Markers and TypoScript
What I want to do is:
Read Data from a MySQL Table (from my extensions preferably)
Compare data with a tt_news Column (Column contains VARCHAR "1,2,3,4")
Look for a certain UID (WHERE tt_news.txy7... CONTAINS uid )
Only output the objects found in the list.
Now I know I should probably build a relational database in the end, containing uid, fahrzeug.uid, tt_news.uid , but I'm really trying to figure out a way to output stuff first.
I think I have a basic thinking mistake in there, but I really need to take a break, since im working nearly 6 hours on this now.
Maybe someone could provide me with some directions?
# Output via Generic Markers
temp.fahrzeuge = CONTENT
temp.fahrzeuge {
table = tx_y7fahrzeugdatenbank_domain_model_fahrzeug
wrap = <div class="tx_y7fahrzeuge_ausgabe">|</div>
select {
selectFields = uid,name,beschreibung
# where = tt_news.tx_y7fahrzeugdatenbank_participate CONTAINS uid
}
renderObj = COA
renderObj {
10 = TEXT
10.wrap = <span class="fzname">|</span>
10.field = name
20 = TEXT
20.wrap = <span class="fzdesc">|</span>
20.field = beschreibung
}
}
plugin.tt_news.genericmarkers {
fzparticipate = COA
fzparticipate {
10 = TEXT
10.value = <h2>Fahrzeuge</h2>
20 = CONTENT
20 < temp.fahrzeuge.renderObj
}
#currentnews = plugin.tt_news.currentUid
}
1) add the whole template to your COA not only the renderObj:
fzparticipate = COA
fzparticipate {
10 = TEXT
10.value = <h2>Fahrzeuge</h2>
20 < temp.fahrzeuge
}
2) make sure you have a pid set for the objects you are selecting and that you in some way set the pidInList option within the select. The result will be empty if you don't!:
select {
#set your pid here
pidInList = 35
# selected fields
selectFields=uid
where = 1=1
}
3) You can add where-clauses in 2 ways: Where & andWhere
3.1) andWhere has a cObject which you can set
table = tx_myTable_mapping
select {
#Do not forget the pid!
pidInList = {$plugin.myPlugin.pid}
#did you know that you can use distinct here?
selectFields=DISTINCT(name)
#you can use a COA here as well, for more complex clauses
andWhere.cObject = TEXT
andWhere.cObject {
#This 3 lines come in handy to prevent SQLInjections
#by fully quoting the GET/POST variable
data = GP:myPostVariable
#tell the system for which table it should do the quoting
fullQuoteStr = tx_myTable_mapping
wrap = myTablefield=|
}
}
3.2) where supports data and wrap options
table = tx_myTable_mapping
select {
#you can do joins as well:
join = fe_users on tx_myTable_mapping.fe_user = fe_users.uid
#again with the pageId
pidInList = {$plugin.myPlugin.pid}
selectFields=tx_myTable_mapping.name as MyLabel
#you can set the where in a static way like you did
#or you use the data and wrap options
where.data = TSFE:fe_user|user|uid
where.wrap = (fe_users.uid = | )
}

extending href programmatically in typo3

What's the best way to extend the attribute href programmatically in Typo3?
The links were setted by RTE like
<a class="download" target="_blank" href="fileadmin/ablage/test_material/pdf_1.pdf">
and shall be changed to
<a class="download" target="_blank" href="fileadmin/ablage/test_material/pdf_1.pdf#zoom=100">
Untested code:
you could try to add the section to the parameter
lib.parseFunc_RTE.tags.link.typolink.parameter.append = TEXT
lib.parseFunc_RTE.tags.link.typolink.parameter.append {
value = #zoom=100
if.equals.data = parameters:0
if.equals.substring = -3,3
if.value = pdf
}
or you can try to use "section"
lib.parseFunc_RTE.tags.link.typolink.section.cObject = TEXT
lib.parseFunc_RTE.tags.link.typolink.section.cObject {
value = zoom=100
if.equals.data = parameters:0
if.equals.substring = -3,3
if.value = pdf
}
BUT the most important issue is the "if" statement. I assume that the first parameter is the name of the file (i do not remember). The last 3 charachters should be "pdf". If you use DAM you need to retrieve the UID and get the filetype from there.
Just a rought guess, this could give you a hint, which params do you have:
lib.parseFunc_RTE.tags.link.typolink.parameter.append = TEXT
lib.parseFunc_RTE.tags.link.typolink.parameter.append {
data = parameters : allParams
htmlSpecialChars = 1
wrap = ?debug=|
}
Just a side note: this would be affect all RTE fields!
If there is a fixed class for that link, you could use jQuery...
jQuery(document).ready(function(){
$('.download').each(function(){
var linkhref = $(this).attr('href');
$(this).attr('href', linkhref + '#zoom=100');
});
});
This code do it.
parseFunc_RTE.tags.link.typolink.parameter.append = TEXT
parseFunc_RTE.tags.link.typolink.parameter.append {
value = #zoom=100
if.equals.data = parameters : allParams
if.equals.substring = -3,3
if.value = pdf
}

Taking a screenshot of a page in InDesign Extension Builder

For my current assignment I need to make an extension for Adobe InDesign using Adobe Creative Suit Extension Builder and Flash Builder. I guess this is more of a question for ones that know Extension Builder and InDesign API.
The point of this extension is to load some data and send some data to a server. I need to make a screenshot of a page, then send it in jpg to a server. But, there are no (or at least i couldnt find any) ways to create a bitmap(to cast it on a object seems impossible, because this Objects are just Objects, and not DisplayObjects).
I managed to silently export pages as jpegs, now I'm thinking about loading them and sending but that will require building an AIR app to handle it all, so this will be a bit bulky.
So to sum up the question, how to take a screencapture of all elements on a page in InDesign using CS Ext.Builder?
what is the problem with export to JPG ? You can choose to export the page or the objects themselves.
Here is a snippet I wrote in a recent project. Hope it helps.
public static function getFilePath():String {
var app:com.adobe.indesign.Application = InDesign.app;
var sel:* = app.selection, oldResolution:Number, oldColorSpace:JpegColorSpaceEnum, groupItems:Array = [], i:int = 0, n:int = sel.length;
if (!sel || !n )
{
Alert.show("Pas de selection !", "title", Alert.OK, Sprite(mx.core.Application.application));
return "";
}
for ( i = 0 ; i < n ; i ++ )
{
groupItems [ groupItems.length ] = sel[i];
}
sel = ( sel.length > 1 )? app.activeDocument.groups.add ( sel ) : sel[0] ;
var tempFolder:File = File.createTempDirectory();
AppModel.getInstance().jpgFolder = tempFolder;
var jpgFile:File = new File ();
jpgFile.nativePath = tempFolder.nativePath + "/temp.jpg";
oldResolution = app.jpegExportPreferences.exportResolution;
app.jpegExportPreferences.exportResolution = 72;
oldColorSpace = app.jpegExportPreferences.jpegColorSpace;
app.jpegExportPreferences.jpegColorSpace = JpegColorSpaceEnum.GRAY;
sel.exportFile ( ExportFormat.jpg, jpgFile );
app.jpegExportPreferences.jpegColorSpace = oldColorSpace;
app.jpegExportPreferences.exportResolution = oldResolution;
if ( sel is Group )
{
sel.ungroup();
app.select ( groupItems );
}
return jpgFile.nativePath;
}