Insert locallang values into TypoScript [stdWrap] - typo3

I wonder if it is possible to insert a locallang value into my typoscript wrap / stdWrap object:
I have:
singleView {
related.wrap = <div class="related">Related items: |</div>
}
What I need is something like that:
singleView {
related.wrap = <div class="related">{LLL:related_items}:|</div>
}
EDIT:
What I am looking for is an TS equivalent for $this->pi_getLL (which works fine).
In our case, we would be replacing values in our extension with
$this->cObj->stdWrap($item, $this->conf['singleView.']['related']);
locallang.xml in extensions /pi1 directory:
<languageKey index="default" type="array">
<label index="related_items">Related items: </label>
</languageKey>

singleView {
related.dataWrap = <div class="related">{LLL:EXT:myextensionkey/pi1/locallang.xml:related_items}:|</div>
}
Of course related_items must be a valid locallang key.
Edit: Do not use wrap with insertData here, because insertData is then run on the whole content, including the user input. If somebody uses {DB:be_users|0|password} inside the content you are wrapping, he can just see the password (hash) of the backend user with uid 0.

Building on the answer of pgampe here, sadly I don't have enough reputation to do it in a comment.
For easier use, do something like this:
constants:
extension.key = myextensionkey
LLL = LLL:EXT:{$extension.key}/Resources/Private/Language/locallang.xlf
and in your typoscript:
singleView {
related.dataWrap = <div class="related">{{$LLL}:related_items}:|</div>
}

Related

Fetching dynamic id and url from image with JS

I'm implementing a fancybox into my project and I'm writing a script to automatically wrap an anchor around the images with the url to the image and a "data-fancybox" attribute to let the fancybox script do its thing. However, I'm only getting the url to the very first image, since they all share the same class. There is a dynamic figure id that seems to be the one to get.
My question is - how do I use this figure id to fetch the appropriate img src?
The html is like this:
<figure id="XXXXXXX">
<div>
<img src="image.jpg" />
</div>
</figure>
... other stuff ...
<figure id="YYYYYYY">
<div>
<img src="image2.jpg" alt="">
</div>
</figure>
My code right now is as follows (which works, but only returns the first image url):
$(document).ready(function() {
var src = $("figure img").attr("src");
var a = $("<a/>").attr( { href:src , "data-fancybox":"" } );
$("figure img").wrap(a);
});
I know I can use
var id = $("figure").attr("id");
to get the id I need, but I'm pretty new to coding so I'm not sure how I implement this and use it to get the correct url. Any help is appreciated!
If your goal is to make your images clickable, then you can do smth like this:
$('figure img').each(function() {
$(this).parent().css({cursor: 'pointer'}).attr('data-fancybox', 'gallery').attr('data-src', this.src);
});
DEMO - https://jsfiddle.net/1jznsL7x/
Tip: There is no need to create anchor elements, you can add data-fancybox and data-src attributes to any element and it will work automagically.

How to implement the sourceCollection responsive image rendering in TYPO3?

I want to implement responsive image rendering according to the different scale (media) in TYPO3 using sourceCollection?
<picture>
<source src="fileadmin/_processed_/imagefilenamename_595cc36c48.png"
media="(max-device-width: 600px)" />
<source src="fileadmin/_processed_/imagefilenamename_42fb68d642.png"
media="(max-device-width: 600px) AND (min-resolution: 192dpi)" />
<img src="fileadmin/_processed_/imagefilenamename_595cc36c48.png" alt="" />
</picture>
I can render it using TypoScript but how can i use this in my own extension?
Thanks in advance.
The most straight-forward way is to use TypoScript. In the example below we use the same configuration I use for tt_content to render News items.
First of all you need to define a TypoScript object that uses the file that is passed to the object. Then you copy the configuration that is used for tt_content.
lib.responsiveImage {
default = IMAGE
default {
file.import.current = 1
altText.data = field:altText
titleText.data = field:titleText
layoutKey = picturefill
layout.picturefill < tt_content.image.20.1.layout.picturefill
sourceCollection < tt_content.image.20.1.sourceCollection
}
}
(You may need to change the example to another layout if you don't want to use picturefill.)
Then, in Fluid, you pass the image to TypoScript. The example below maps the uri of a FileReference:
<f:alias map="{image: {uri: '{f:uri.image(src:\'{mediaElement.uid}\', treatIdAsReference:\'1\')}', altText: mediaElement.originalResource.alternative, titleText: mediaElement.originalResource.title}}">
<f:cObject typoscriptObjectPath="lib.responsiveImage.default" data="{image}" currentValueKey="uri" />
</f:alias>
You can also define other configuration, e.g.
lib.responsiveImage {
default = IMAGE
default {
[...]
}
newsDetail < .default
newsDetail {
[different configuration for type newsDetail]
}
}

Create a subpart menu for a one page template in typo3

I integrate a one page parallax template in typo 3 in this i want to get a menu like below so i can access specific content on click , in a subpart of page object.
<ul class="nav navbar-nav navbar-right">
<li>HOME</li>
<li>ABOUT</li>
<li>PRICING</li>
<li>CONTACT</li>
<li>Call: +23-689-90 </li>
</ul>
Try
temp.contentnav = CONTENT
temp.contentnav {
table = tt_content
select {
pidInList = this
orderBy = sorting
where = colPos=0
languageField=sys_language_uid
}
renderObj = TEXT
renderObj {
field = header
wrap=|
typolink.parameter.field=pid
typolink.parameter.dataWrap=|#{field:uid}
if.isTrue.field=header
}
}
So you will get an menu of all items. Then again, you won't like that the menu item's title is taken from the header field. If your site is very small and you keep control over it, why don't you just hardcode this (look at the source, by default, each article has an id).
PS I copied that from http://www.typo3wizard.com/en/snippets/menus/content-element-navigation.html
EDIT on your getting started with TS question:
In your HTML Template:
<html>...
<!-- ###CONTENTNAV### START --><!-- ###CONTENTRIGHT### END -->
...</html>
In your TypoScript setup:
page.10.subparts {
# we fill the "subpart" (that's how this type of marker is called) with the temp object
CONTENTNAV < temp.contentnav
}
So the caret pointing left tells TYPO3 that in that region ("subpart"), it should add the content menu you've created with the TS snippet.
Note that you can also use "Marks" (###CONTENTNAV###, don't need start and end commentary, assign with page.10.marks) and the more modern fluid templates (<f:format.html>{contentnav}</f:format.html>), which are the future. You could start here: http://typo3buddy.com/typo3-template-tutorial/fluid/

TinyMCE - applying a style over bullets and multiple paragraphs applies the style to each bullet & para - how do I avoid?

I'm trying to use the theme_advanced_styles command within TinyMCE to add classes to selections of text within the TinyMCE editor. The problem is that if the paragraph contains bullets, then the style is applied throughout them (as well as to each individual paragraph).
What I want is just for the entire selection I made to have the style class added to the start of it. Ie if my style class is 'expandCollapse' I want:
<p class="expandCollapse">some content... some content... some content... some content... som content... some content... some content...
<ul>
<li>asdsadsadsadsasda</li>
<li>asdsadsa</li>
<li>sada</li>
</ul>
asome content... some content... some content... some content... some content... some content... some content... some content... </p>
But what I get is:
<p class="expandCollapse">some content... some content... some content... some content... some content... some content... some content...
<ul>
<li class="expandCollapse">asdsadsadsadsasda</li>
<li class="expandCollapse">asdsadsa</li>
<li class="expandCollapse">sada</li>
</ul>
</p>
<p class="expandCollapse">asome content... some content... some content... some content... some content... some content... some content... some content... </p>
Any ideas anyone?!
So I had to answer my own question as I needed an answer very quickly. It appears the behaviour I was experiencing is intentional? and certainly not something that has been removed in the very latest versions of TinyMCE (both 3.x and 4.x after testing).
With this in mind I ended up having to make a plugin to do what I wanted.
I borrowed a huge amount of code by Peter Wilson, from a post he made here: http://www.tinymce.com/forum/viewtopic.php?id=20319 So thanks very much for this Peter!
I ended up slightly changing the rules from my original question in that my solution adds an outer wrapping div around all the content I want to select. This method also allowed me to reliably then grab the required areas of html with jQuery in my front-end site.
My version of Peter's code is just very slightly modified from the original in order to add a class to the DIV, rename it, use a different button etc.
The plugin works perfectly and allows for a div to be created wrapping any amount of content within TinyMCE. The divs inserted have the class name I need also applied to it.
Add 'customDiv' to your plugin AND button bar for it to appear.
(function() {
tinymce.create("tinymce.plugins.Div", {
init : function(editor, url) {
editor.addCommand("mceWrapDiv", function() {
var ed = this, s = ed.selection, dom = ed.dom, sb, eb, n, div, bm, r, i;
// Get start/end block
sb = dom.getParent(s.getStart(), dom.isBlock);
eb = dom.getParent(s.getEnd(), dom.isBlock);
// If the document is empty then there can't be anything to wrap.
if (!sb && !eb) {
return;
}
// If empty paragraph node then do not use bookmark
if (sb != eb || sb.childNodes.length > 1 || (sb.childNodes.length == 1 && sb.firstChild.nodeName != 'BR'))
bm = s.getBookmark();
// Move selected block elements into a new DIV - positioned before the first block
tinymce.each(s.getSelectedBlocks(s.getStart(), s.getEnd()), function(e) {
// If this is the first node then we need to create the DIV along with the following dummy paragraph.
if (!div) {
div = dom.create('div',{'class' : 'expandCollapse'});
e.parentNode.insertBefore(div, e);
// Insert an empty dummy paragraph to prevent people getting stuck in a nested block. The dummy has a '-'
// in it to prevent it being removed as an empty paragraph.
var dummy = dom.create('p');
e.parentNode.insertBefore(dummy, e);
//dummy.innerHTML = '-';
}
// Move this node to the new DIV
if (div!=null)
div.appendChild(dom.remove(e));
});
if (!bm) {
// Move caret inside empty block element
if (!tinymce.isIE) {
r = ed.getDoc().createRange();
r.setStart(sb, 0);
r.setEnd(sb, 0);
s.setRng(r);
} else {
s.select(sb);
s.collapse(1);
}
} else
s.moveToBookmark(bm);
});
editor.addButton("customDiv", {
//title: "<div>",
image: url + '/customdiv.gif',
cmd: "mceWrapDiv",
title : 'Wrap content in expand/collapse element'
});
}
});
tinymce.PluginManager.add("customDiv", tinymce.plugins.Div);
})();

iMacros - How do I TAG URL with unique surrounding html?

I need to extract "https://www.somesite.com/Some.Name.123" from the code below.
That code segment is repeated many times, and I need the URLs ..Some.Name.X.
There are other code segments between each of the ones I'm interested in, with very different surrounding html. I don't need the ..Some.Name.x URLs in those other segments.
The following is unique to what URLs I need: "<a class="-cx-PRIVATE-uiImageBlock__image"
<div class="clearfix pvm">
<a class="-cx-PRIVATE-uiImageBlock__image -cx-PRIVATE-uiImageBlock__largeImage lfloat"
aria-hidden="true" tabindex="-1" href="https://www.somesite.com/Some.Name.123">
I don't know how to tag that preceding HTML with iMacros, or how to do that with jQuery as the structure will a bit different each time, but you could to this.
Save the web pages with iMacros. Write a program (c, etc.) to read each of the saved files and write the URLs that follow "cx-PRIVATE-uiImageBlock__image" to a file. Add that list of URLs to an iMacro, or have iMacros read the file, and then process each URL from iMacros.
You need to use some scripting.
My answer makes use of jQuery
var listoflinks = []; //array containing your links
$('a[href*="somesite.com"]').each(function () { // for each link that contains somesite.com in href
var j = $(this).attr('href'); //put the whole href in a variable
listoflinks.push(j); // put all values in an array
});
you'll end up with an array that contains all the href values you're looking for.
If you want to see an example and/or you want to play around with the script you can go here:
http://jsfiddle.net/flish/rESjg/
Edited
Your code is still not clear enough, but hopefully this may help
<a class="sibling a" href="link">sibling a</a><br />
<div class="sibling div"><br />
<a class="child a" href="start-with-link/correct-link">Child a</a><br />
</div><br />
Above is the markup I've used. What this means is that I have considered that you have the following elements:
a // with a sibking div
div // with a child a
a // and all of them have appropriate classes
For this markup you can use the following code (jQuery, of course)
var listoflinks = []; //array containing your links
$('a[class="sibling a"]').siblings('div[class="sibling div"]').children('a[class="child a"]').each(function () {
if ((($(this).attr("href")).substring(0,15))=="start-with-link"){
var i = $(this).attr("href");
listoflinks.push(i);
}
});
View detailed example at http://jsfiddle.net/flish/HMXDk/
Be that as it may, you can add more sibling and children elements in case you have other html entities you forgot to mention
<a class="-cx-PRIVATE-uiImageBlock__image" ------------------ <div class="clearfix pvm"> <a class="-cx-PRIVATE-uiImageBlock__image -cx-PRIVATE-uiImageBlock__largeImage lfloat" aria-hidden="true" tabindex="-1" href="somesite.com/some.name.123">
For example, what means ------------------ in your code above?