Best way to declare content element uids to use them in fluid templates - typo3

I want to display some contentlement on every page with fluid templates. My solution was to create a typoscript element like:
lib.my.myelement= CONTENT
lib.my.myelement {
table = tt_content
select {
pidInList = 15
where = uid=99
}
}
and then use it in the fluid template with:
<f:cObject typoscriptObjectPath="lib.my.myelement" />
Another way is to create them directly in fluid with v:content.render or v:content.get. In this example I get all content elements on one page and save them in an array:
<v:variable.set name="contentElements" value="{v:content.get(column:'0', limit:'3', pageUid:'9', render:'FALSE')}" />
I can not use the first solution, cause on this page there will be much different languages ( I could use it, but every time a new language is added I would have work to declare all new uids of the new elements in typoscript).
The second solution would work better, cause when you translate a page the element uids change, but the pageUid does not change. But here I have the problem that I don't just need all elements, I also have to identify each element.
Here is how I use the second solution:
<v:variable.set name="contentElements" value="{v:content.get(column:'0', limit:'3', pageUid:'9', render:'FALSE')}" />
<f:for each="{contentElements}" as="contentElement" iteration="footerIteration">
<div class="column{v:math.sum(a: footerIteration.index, b: 1)}">
<v:content.render contentUids="{0:contentElement.uid}" />
</div>
</f:for>
As you can see, I use every element the same way.
lets create a simple case:
I have a page with the pageUid = 10 (this page will have translations). On every of this translations will be 3 elements. Lets say 1 element got the "id" (with id I mean something how I can identify this element) title1 and the other two elements have the id list1 and list2.
And my question now is How could I access for example list1?
I hope its understandable, if something is not clear please leave a comment.
Edit: I could use the same order on every translation for the elements and then check the iteration in the for-loop (see the second solution) to identify them. But I wonder if there a better, cleaner way.

Related

TYPO3 9 and Flux: Adding an element / section / container multiple times

I'm using TYPO3 9.5.26 and Flux 9.4.2 and I would like to create a calendar-element with exactly five elements/days. Each day needs some input fields. It would look something like this:
Calendar:
Day 1: Offer ID, Image
Day 2: Offer ID, Image
Day 3: ...
Considering DRY, I would like to use some kind of for-loop, but this doesn't work. What I tried:
<f:section name="Configuration">
...
<f:for each="{0:1, 1:2, 2:3, 3:4}" as="foo" key="number">
<flux:field.multiRelation label="Angebot Tag 1" name="offerDay1" table="tx_data_domain_model_offer">
</flux:field.multiRelation>
</f:for>
If I enter five of the multiRelation-fields, it works as expected but as these subelements will get more input fields the code would get bloated.
I also tried using a flux section but it seems like there is no option of limiting the number of elements to exactly five.
Thanks to j4k3's last comment on my question I found out what I was doing wrong: I was trying to apply multiple fields with the same name which isn't allowed. This code using the 'key' works (could also use iteration):
<f:for each="{0:1, 1:2, 2:3, 3:4}" as="foo" key="number">
<flux:field.multiRelation label="Angebot Tag {number}" name="offerDay{number}" table="tx_data_domain_model_offer">
</flux:field.multiRelation>
</f:for>

TYPO3 Understanding BE Layout + Template

I am new to TYPO3 and tried out a little bit so far. Now I am stucked or lets say unsure if it's the right way how I would do it.
First I created a simple HTML file and put some CSS to it. When this simple site was finished, I tried a transition to TYPO3 and created some templates + typoscript code. Now I want to work on the content, so I can create this with the integrated editor in TYPO3 and remove it from my templates.
My site would look like this:
Header
News Row (4 Columns)
Another Content Row (3 Columns)
Another Content Row (3 Columns)
Footer
Header and Footer are in partials and don't get any content from the editor. For the news section I would use a plugin. The other content rows have to be filled with content from the TYPO3 editor so my first thoughts are that my backend layout must look like this:
News Row (do I need 4 columns here or just one and let the plugin work?)
left1 center1 right1
left2 center2 right2
Would the backend layout look like this? And for the implementation with typoscript do I have to write all columns in variables e.g. center < styles.content.get... and create all elements in the columns there or can I outsource every variable in one file for example?
Hope you guys understand my problem and can give me some good hints!
About the news row, use just one column and then modify the EXT:news templates to arrange the list of news on four columns;
About the other two rows, you have several options, I think
1) each "cell" is defined in your backend layout, and then yes, you would need a separate colPos for each, something like (in TypoScript):
center < styles.content.get
left < styles.content.get
left.select.where = colPos = 1
2) Same as 1) but you can use the interesting approach used by Benjamin Kott on his sitepackagebuilder . To make it short, he defines a "dynamicContent" TypoScript object that can accept as parameters the colPos and even the id of a specific page. You just write in yout Fluid Template:
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '0'}" />
And so forth for the others. If you want to discover more, visit https://www.sitepackagebuilder.com/ and create a package (that you could use as a base for your development or just "pillage" it ;) ) You will also find several videos on this topic on the Youtube TYPO3 official channel
3) same as 1) but using the EXT:vhs that adds a specific viewhelper to render the content of a colPos:
<v:content.render column="0" />
4) Last but not the least you can use EXT:gridelements to build content element that can have other content elements as children with a "backend_layout" approach. In this approach you just need one "cell" in your backend layout, and in this cell you will put a "gridelement" CE that is sub-divided into three separate columns and in each one you can put one or more content elements (same for the third row). This approach will give you the maximum flexibility
I hope I made myself clear, if I misunderstood your question, don't hesitate to write :)

Add additional source to Image for further actions

im trying to add an additional source to the dce-image for further actions e.g. an alternate source to perform some JavaScript actions.
The wanted output should look like this:
<img src="path/to/foo.png" data-altsrc="path/to/bar.png">
The problem is the dce i'm using - its iterating through the "images" like this:
<f:for each="{dce:fal(field:'image', contentObject:contentObject)}" as="fileReference">
<f:image src="{fileReference.uid}" treatIdAsReference="1" />
</f:for>
So if I would insert multiple images to this I have no real relation between the images where i know which one is the normal-source and which one is the alternate source.
So there was the possibility to create a section and add two fields for images which we can restrict to one image per field. But there again is the for-loop which doesn't allow me to access the source of the second image for the first image.
It should be a visible relation between these images for the user which is working with the dce.
Im trying to achieve something like this:
<f:for each="{field.images}" as="images">
<!-- want to achieve something like this -->
<f:image image="{images.foo.src}" data-altsrc="{images.bar.src}">
<!-- thats the normal way iterating through images -->
<f:for each="{images.foo}" as="image">
<f:image image="{image}" />
</f:for>
</f:for>
Another idea would be to iterate first through the alternate images and store them into an array and on the main-images to access them but I have no idea if this is even possible also this will restrict the usability of the dce for the user.
Is there any way to achieve this with dce-fluid ?
Thanks in advance
Well, i guess you could extend the sys_file_reference table to add a relation from there. So you would have nested relations (never done that, so you would have to try).
You would also have to add the field to the tca type in the place you need it, that could be a little tricky. Have a look at Tca types overrides.
You could extend the sys_file_reference table with a field "alternative_reference" and add the neccessary TCA setup. Then you would have to retrieve the FileReferences via the FileRepository and use sys_file_reference as foreign table (and of course the sys_file_reference uid as identifier).
FileRepository::findByRelation(
'sys_file_reference',
'alternative_reference',
$uidOfActualSysFileReferenceRecord
);
The other possibility would be a completely new record with 2 different sys_file_reference relations. That record (eg: tx_ext_domain_model_imageset) would have an image_default and image_alternate field, both would be configured as file_relations. That would work for sure.
$defaultImages = FileRepository::findByRelation(
'tx_ext_domain_model_imageset',
'image_default',
$uidOfRecord
);
$alternativeImages = FileRepository::findByRelation(
'tx_ext_domain_model_imageset',
'image_alternative',
$uidOfRecord
);
I assume you do have knowledge about creating records, models, tca and so on.
I personally would prefer the second way, it is more clean and does not change the core-table structures.
Also there is a second image generation viewhelper, that might suite your needs better
<img src="{f:uri.image()}" data-altsrc="{f:uri.image()}" />
But the best way to go might be to write your own ViewHelper for that purpose. You could pass your Object (ImageSet) as parameter and handle all logic there. So your template would be simpler and easier to read/work on.
You have to use data attribute of fluid viewhelper and then get the uri of the image with inline call. Here is how to achieve :
<f:image src="{fileReference.uid}" data="{altsrc: '{f:uri.image(src: \'{fileReference.uid}\', treatIdAsReference: 1}" treatIdAsReference="1"/>
This should do the work.

Is it possible to find and store element's location by text in selenium ide?

I need to create the element and then delete it. Is there a way to find the element by it's text after it was created?
The xpath of the element is //div[#id='mif-tree-6']/span/span[3].
You can use xpath for it for example. Like:
//div[#id='mif-tree-6']//span[contains(text(),'your_text_here')]
UPDATE
Please provide an example of your html. It is possible to find a parent of your element with xpath and after that to find all the childs. For example your html =
<div id='lol'>
<div>first_item</div>
<div>second_item</div>
<div>third_element</div>
</div>
You get an array of elements with xpath =
//div[contains(text(),'first_')]/../div
So you can do something like:
click | //div[contains(text(),'first_')]/../div[2]
BUT if there are a lot of brothers-elements to find by text of one sibling it will be necessary to use loop to get every of them.
Once again. If you will provide full information about what are you doing and an example of your html it will be much easier to suggest.

Selecting last child with specific id

So here is the thing:
<div id="wrapper" > <div id="x"></div ><div id="x"></div ><div id="x"></div><div id="y"></div>
</div>
So how do i select last div with id=x not y inside of wrapper? Sorry , but i dont know how to pase code to be visible.
An ID is unique so to select it you should just be using
#x {}
I would question why you are using multiple id's though, maybe a class would be better?
Edit
Just noticed you pasted some code.
You really shouldn't be using ID's the way you are, you need to be using classes replace your id's with:
class="x"
If only for modern browsers you can use the last-of-type selector
.x:last-of-type
if going back to IE6 you can always add a class like last and then select it
class="x last"
.x.last {}
Edit For question
To use your wrapper selection you add it to the front of your selector:
#x .x.last {
/** css goodness here **/
}