How to add an id to image in typo3? - typo3

I am struggling with typo3. I want to add a default id to a particular image uploaded in a section by user.
My backend layout create a section with colPos = 1.
In this section user can upload one image, which will have id of
bg-img
I have cleared default rendering of image by this code:
tt_content.image.20.1.layout.default.element = <img src="###SRC###" ###ALTPARAMS###>
My template code is like this:
page.10.subparts {
HEADERIMG<styles.content.get
HEADERIMG.select.where = colPos= 1
}
How to do that?

I don´t think having multiple images with the same id on a page is correct HTML, as ID´s should always be unique per page. Use the class attribute instead. With the following code you can specify image params.
tt_content.image.20.1.params = class="my-class" id="bg-img"

Related

Powermail/Typo3: prefill form field using image title

Using Typo3 8.7.4/Powermail 3.21.2
I'm pretty new to Typo3, so I have no clue if this is even the right way to do it, but heres my problem:
On the site there are several subpages with images/descriptions of articles on them. Every article has an UID stored in the image title (dont ask me why).
When an image is clicked it links to another page with a powermail mailform.
In this form there's a textfield for the UID which should automatically fill with the UID in the image title so the user doesn't have to do it manually. That essentially it.
I know you can prefill a field with a value or placeholder, but should I even use a textfield or use TS instead?
And what should I add to the image link for the UID to get posted to the form?
Or am I doing this completely wrong?
All help appreciated, thank you and have a nice day!
You can Do like This.
plugin.tx_powermail.settings.setup.prefill {
position = CONTENT // Here Position is your powermail form fields
position {
table = Your tables
select {
selectFields = title
andWhere.data = GP:title // Pass your url parameters
andWhere.wrap = uid=|
pidInList = 108 // Added Your Pid
}
renderObj = TEXT
renderObj.field = title
}
}
There are several ways of prefilling form fields in powermail (look at the manual https://docs.typo3.org/typo3cms/extensions/powermail/ForAdministrators/BestPractice/PrefillField/Index.html) and I would say that there is no wrong way. Just choose the right one for your needs.

Adobe CQ5.5-How to display Page Thumbnail using API

I have configured image for my page using sidekick >Page properties>Images tab. Now I want to fetch my this page image(thumbnail) in one of my jsp. Can someone give me pointers or code snippet for api class and method that I can use to achieve this.
Thanks,
Rajeev
I would suggest using the default image component as an example - /libs/foundation/components/image.
If you're putting your code into a component for your specific page type though, your code should be something like this:
if (currentNode.hasNode("image")) {
String imagePath = currentNode.getNode("image").getPath();
Resource imageRes = resourceResolver.getResource(imagePath);
image = new Image(imageRes);
image.loadStyleData(currentStyle);
image.setSelector(".img");
if (!currentDesign.equals(resourceDesign)) {
image.setSuffix(currentDesign.getId());
}
image.draw(out);
}
Keep in mind though, even though you set an image, it does NOT mean it will show up - if you're using the default page dialog for page properties, it will only show a broken image. That's because there is a bug in CQ where the sling:resourceType property of the image doesn't get set, and thus it won't show up. This is because the .img selector that gets put on the image doesn't know what to do, unless it get's pointed to a resource type with a definition for the .img selector, so it can properly render the image.
I've uploaded a package that you can use as a hotfix for the issue with the default /libs/foundation/components/page component dialog, so that it will actually set the resource type when you upload an image. You can find/download the package from my Google Drive
Hopefully that helps. Let me know if you need more help.
EDIT
If you're trying to get the page properties image from one page on another page, you just need to use a resource resolver. You should have one available to you in CQ, so this would essentially be the code:
Resource imageRes = resourceResolver.getResource(pathFromYourDialog);
Image image = new Image(imageRes);
The rest would be the same - you're just giving it a different path to start from.
I think Nicholaus was more on point with his EDIT answer to your immediate need. If the user is providing you a path to the thumbnail via the dialog (i.e. a DAM image).
You can simply create the image, or if it has DAM information you can load it as a DAM Asset and pull the necessary information.
Image image = new Image();
Resource imageResource = resourceResolver.getResource(imageUrl);
Asset imageAsset = imageResource.adaptTo(Asset.class);
Map<String, Object> valueMap = imageAsset.getMetadata();
long width = Long.parseLong(valueMap.get("tiff:ImageWidth").toString());
long height = Long.parseLong(valueMap.get("tiff:ImageLength").toString());
Object titleObject = valueMap.get("tiff:ImageTitle");
String title = (titleObject == null) ? null : titleObject.toString();
if (title != null)
{
image.setTitle(title);
}
image.setWidth(width);
image.setHeight(height);
image.setUrl(imageUrl);
This is a little long hand for what Nicholaus had suggested, the Image class will create itself based off the Resource you pass it. (actually upvoted Nicholaus for that, have some optimizations we can make).
Another, simpler option would be to just use the src that the user passes through, in the event that all you're doing is setting a thumbnail. I'm guessing you could be safe in doing something like:
in java:
String thumbSrc = properties.get("thumbSrc", "defaultThumbnail.path");
if (!thumbSrc.isEmpty())
{
pageContext("thumbSrc", thumbSrc);
}
in jsp:
<img alt="thumbnail" src="${thumbSrc}"/>
or if you don't want to do anything in the java you could just do something like
<c:if test="${not empty properties.thumbSrc}">
<img alt="thumbnail" src="${properties.thumbSrc}"/>
</c:if>
In order to get the same result as the first part in just jsp, you'd need to wrap it in a choose, because passing it through some processing before sending to view makes it easier to set default values.

tt_news: fancybox for images inserted in RTE

Users should be able to insert images on a news. If they are inserted they should open with fancybox. Therefore I installed jqfancybox. Now the images added as media opens in the fancybox and the user is able to click through all images (like a gallery). What do I have to do to also open images inserted by the RTE?
I tried the following typoscript:
plugin.tt_news.displaySingle.image.imageLinkWrap {
JSwindow = 0
directImageLink = 1
linkParams.ATagParams {
dataWrap = class="jqfancybox" rel="fancybox"
}
}
The idea is if an user inserts an image with the option "click enlarge" the above shown class should be added as well as the rel attribute. The rest should do the fancybox. But for existing images no class is added and fancybox doesn't pop up. What I'm missing?
Edit:
Now I tried it with:
plugin.tt_news.displaySingle.content_stdWrap.parseFunc {
postUserFunc.imageLinkWrap.typolink{
ATagParams {
dataWrap = class="jqfancybox" rel="fancybox"
}
}
}
but the link is not wrapped.
RTE content is parsed via parseFunc < lib.parseFunc_RTE. So if you want to change the config, you need to configure plugin.tt_news.displaySingle.content.parseFunc.* (i am not sure, if the field is content or bodytext or whatever)
lib.parseFunc_RTE is a default Config for parsing RTE content. It is quite powerful, but you need to lookup a lot of TypoScript functions.

How can I insert the current page title automatically into a TYPO3 template?

actually the title is the whole question.
I just want to modify the template so that the current page title is automatically shown (i'm working with html templates so I just need the bit of typoscript to get the page title out of the database)
I hope that's possible
It is. It's pretty simple to do. I'll assume you're using TemplaVoilà, because if you're not, you should be :-D
Start off by putting some HTML in your template with a dummy page title. Give it an ID attribute so it's easy to map. Like:
<h1 id="page-title">Page Title Here</h1>
Next, go into TemplaVoilà and map that <h1> element to the content type "TypoScript Object Path". When it prompts you for the object path, you can put in anything you want -- convention is that dynamic content is added in the "lib" namespace, so let's call it lib.pagetitle. When it asks you if you want to map this to "INNER" or "OUTER", choose "INNER" -- that will mean you're just mapping the space BETWEEN the <h1>...</h1> tags. ("OUTER" means you're replacing the whole element, including the tags, which we don't want here because we want this to stay an H1.) Save your template mapping.
Now go into your site's TypoScript template. Here you're going to insert the logic that fills in that space we just mapped with actual content. To insert the page title is a matter of a couple of lines of TypoScript:
lib.pagetitle = TEXT
lib.pagetitle.data = page : title
What this says is "take the space in the template that I mapped to lib.pagetitle. Create a content object in that space of type TEXT. Then fill that content object with the title of the page."
Save your TypoScript template. Now you're done!
This probably sounds complicated at first glance, and it is, but the nice thing about this system is that it's amazingly flexible. Inserting text dynamically is just the beginning. The TypoScript Reference (a.k.a. the "TSRef") has all the details -- look up "getText" to get a flavor, that's the function that makes the "page : title" call in your TypoScript template drop in the page title.
TSRef is your friend. I keep a printed copy of it at my desk -- if you want to make TYPO3 sing, it is your songbook.
I prefer the vhs solution:
{v:page.info(field:'title')}
https://fluidtypo3.org/viewhelpers/vhs/master/Page/InfoViewHelper.html
lib.pagetitle = RECORDS
lib.pagetitle {
source.data = page:uid
tables = pages
conf.pages = TEXT
conf.pages.field = nav_title
}
To get current page title:
lib.pagetitle = TEXT
lib.pagetitle.field=title
For meta data :
Its very important to place meta after header tag when we are gone through mobile compatible website
In order to prevent quirks mode in IE9 I need to add this lines at the very top of every HTML page:
You can write the whole header by yourself, by adding disableAllHeaderCode = 1 to your typoscript or you can hack it by adding your meta tag directly to the head tag:
page.headTag = <head><meta http-equiv="X-UA-Compatible" content="IE=edge" />
Place this at your typoscript
meta.X-UA-Compatible = IE=edge,chrome=1
httpEquivalent: (Since TYPO3 4.7) If set to 1, the http-equiv attribute is used in the meta tag instead of the “name” attribute. Default: 0.
For more information about TYPO3 stuff you may visit my blog
https://jainishsenjaliya.wordpress.com/2013/10/10/put-meta-tag-on-top-of-header-section-in-typo3/
If you want to use this in a fluid page template, you can also simple use:
{data.title}
to access the page title.
You can current page title by following typoscript:
lib.pagetitle = TEXT
lib.pagetitle.data = page : title
and then use this object to your page using typoscriptObjectPath like following way:
<f:cObject typoscriptObjectPath="lib.pagetitle"/>
If you want to use a fluid only solution, install the VHS extension and you can output the page title without using any TypoScript at all like this:
Tag Example:
<v:page.header.title title="NULL" whitespaceString="' '" setIndexedDocTitle="1">
<!-- tag content - may be ignored! -->
</v:page.header.title>
Inline Example:
{v:page.header.title(title: 'NULL', whitespaceString: '' '', setIndexedDocTitle: 1)}
lib.page_title = CONTENT
lib.page_title {
table = pages
select {
where = uid = 2
}
renderObj = COA
renderObj {
10 = TEXT
10 {
field = title
wrap = <h1 class="page_title">|</h1>
}
20 = TEXT
20 {
field = subtitle
stdWrap.required = 1
stdWrap.wrap = <h5>|</h5>
}
}
}
call the lib.page_title where want to render typoscript with this lines
<f:cObject typoscriptObjectPath='lib.page_title' />
I hope this helps !!!
The question is quite old but I still want to add something I never read here.
TYPO3 offers many things concerning the header, and it's right that it's also possible to render it completely individual. Nevertheless all the nice options of TYPO3 are more or less disabled by the individual solution.
So first the direct answer on the question:
The default page title can be overridden like this
config.pageTitle.stdWrap.override.cObject < lib.pagetitle
If several page types are defined and the title shall be set individually for each type, the configuration can be noted inside the page-definitions:
page = PAGE
page {
typeNum = 0
config.pageTitle.stdWrap.override.cObject < lib.pagetitle_1
...
}
anotherPage = PAGE
anotherPage {
typeNum = 1
config.pageTitle.stdWrap.override.cObject < lib.pagetitle_2
...
}
Below still a lib.pagetitle which makes a little bit more than only using title or subtitle - it uses news-title if the extension is used on a page:
lib.pagetitle = COA
lib.pagetitle {
10 = TEXT
10 {
// subtitle: used as field for title tag
value.field = subtitle // title
if.isFalse.data = GP:tx_news_pi1|news
}
20 = RECORDS
20 {
if.isTrue.data = GP:tx_news_pi1|news
dontCheckPid = 1
tables = tx_news_domain_model_news
source.data = GP:tx_news_pi1|news
source.intval = 1
conf.tx_news_domain_model_news = TEXT
conf.tx_news_domain_model_news {
field = title
htmlSpecialChars = 1
}
}
}
Now still some background why I think some individual header might not be the best solution:
TYPO3 usually adds several details to the header, that are useful and it's not required to combine those things individually new.
Scripts and stylesheets are organized and can be even by TypoScript compressed and merged. If some syntax is followed it even takes care that a library like jquery is only included once.
TYPO3 has many functions in TypoScript where everything can be defined related to the header and also it can be decided if scripts shall be perhaps never be included at all in the header but instead in the bottom of the page-source.
Metatags can be defined (and overridden by extensions or sub-templates)
Implementing this whole logic manually again in an own template in my opinion is not useful and I think headers should be only disabled for special page-types like AJAX or dynamic PDF-files. This is the primary reason that I consider that option as useful.
Her still the current link for the most recent documentation about the config-options in TypoScript (anchor pagetitle):
https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html#pagetitle

TYPO3: How do I insert page content into template

I have some content that I want to appear on multiple pages of my TYPO3 site. I could just insert this into the template, but I also want that content to be editable in the Rich Text Editor.
So I had the idea of creating a hidden page, but I don't know how to insert this content into a template.
Does it require the select typoscript statement?
Also, as a follow-up question, can I add something to say, only include pages that have this page id as their immediate parent in the page hierarchy.
I didn't quite get the second question.
If you want to include some record only to pages under some other page, then this will obviously work:
[PIDinRootline = pages-uid, pages-uid, ...]
temp.foo = RECORDS
temp.foo {
tables = tt_content
source = ID # Enter the object's ID here
}
[end]
On the other hand, if you want to include all records from pages, being children of some other page, then try something like:
1 = CONTENT
1.table = tt_content
1.select {
pidInList = parent-uid
}
Don't know if I got you right though.
Dmitri.
From Include typo3 content elements on every page:
temp.foo = RECORDS
temp.foo {
tables = tt_content
source = ID # Enter the object's ID here
}
Note the ID is the content record ID, not the page ID.
But that doesn't answer the question of how to only include pages/records with a certain parent.
You can set up a hidden page and then "import" the content elements on a given page via typoscript on the pages (or the entire page tree below) as needed.
The "trick" is to use the colPos with the select-statement. With this you can even put multiple (different) content elements in one (hidden) page that show up on different pages (depending on the setting of the column they are "in".
Example:
Create a hidden (or system) page (here example-pageid = $PID_STATIC)
Create a content element on this page (text)
Edit this content element to be shown on the right column (right equals colPos=2)
Put the following typoscript into the template on which you want the content element to be shown. You can set the pid (pageId) in the constants via PID_STATIC or "hardcode" it into the typoscript.
.
lib.aditionalcontent = COA
lib.aditionalcontent {
10 = CONTENT
10 {
table = tt_content
select.where = colPos = 2
select.orderBy = sorting
select.pidInList = {$PID_STATIC}
}
Add the element lib.aditionalcontent into your template where the content should be shown. For example:
.
page.10 = TEMPLATE
page.10.template = FILE
page.10.template.file = fileadmin/maintemplate.htm
page.10.workOnSubpart = DOCUMENT_BODY
page.10.marks.ADITIONAL_CONTENT < lib.aditionalcontent
.
Watch out, that you set the colPos according to the column that you have set the content element into, otherwise it just will not show.
You can use different columns to do this for different content that has to show up/should not show up on a particular page.
This also works with sytemfolders and non-hidden pages.
If you use TemplaVoila, this should also work although you have to switch to the listview to see and set the colum for the content element (if not hidden for this non-admin user).
To find out which colPos-number is which position of the column go to the phpMyAdmin and search for the field "colPos" in the tt_content table.