How to render INT_SCRIPT in StandaloneView? - typo3

I'm rendering in an standalone view a TypoScript Object with the cObject ViewHelper. That TS Object gets tt_content from other pages currently. But the result has the INT_SCRIPT markers and not the real content.
here's my code on how to make the standalone view, the template and the TypoScript:
Inside controller:
public function renderStandaloneView($template = 'View/Show', $variables = array(), $fileExt = 'html', $noCache = TRUE) {
if ( $noCache === TRUE ) $GLOBALS['TSFE']->set_no_cache();
// Get standalone view
$configuration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$view = $this->objectManager->get(StandaloneView::class);
$view->getRequest()->setControllerExtensionName($this->extensionName);
$view->setFormat($fileExt);
$view->setLayoutRootPaths($configuration['view']['layoutRootPaths']);
$view->setPartialRootPaths($configuration['view']['partialRootPaths']);
$view->setTemplateRootPaths($configuration['view']['templateRootPaths']);
$view->setTemplate($template);
// Render view
$view->assignMultiple($variables);
return $view->render();
}
TypoScript:
lib.myContent = COA
lib.myContent {
10 = CONTENT
10 {
table = tt_content
select {
orderBy = sorting
where = 0
where.wrap = colPos=|
pidInList.field = uid
}
}
}
Fluid:
<f:for each="{myvars}" as="myvar" iteration="it">
<f:cObject typoscriptObjectPath="lib.myContent" data="{uid:'{myvar.uid}'}" />
</f:for>
I cannot change all the uncached elements (like content elements / plugins) on that pages to be cached.
So how can i parse the standalone view including the non cached content and not insert the INT_SCRIPT markers?
Thanks for anything!

Found a solution. Maybe it isn't the best way to resolve that problem. But at the moment it works fine.
public function renderStandaloneView($template = 'View/Show', $variables = array(), $fileExt = 'html') {
// Get standalone view
$configuration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$view = $this->objectManager->get(StandaloneView::class);
$view->getRequest()->setControllerExtensionName($this->extensionName);
$view->setFormat($fileExt);
$view->setLayoutRootPaths($configuration['view']['layoutRootPaths']);
$view->setPartialRootPaths($configuration['view']['partialRootPaths']);
$view->setTemplateRootPaths($configuration['view']['templateRootPaths']);
$view->setTemplate($template);
// Render view
$view->assignMultiple($variables);
// Handle the INT_SCRIPT markers
$content = $view->render();
$contentBak = $GLOBALS['TSFE']->content;
$GLOBALS['TSFE']->content = $content;
$GLOBALS['TSFE']->INTincScript();
$content = $GLOBALS['TSFE']->content;
$GLOBALS['TSFE']->content = $contentBak;
unset($contentBak);
return $content;
}
For your information. I need this to handle content from pages and send them by mail or render a pdf with an external tool. But some content or pages are only available for the current user (not a group or another user). And i didn't want to login that user inside the controller or else. i think that's the best case to handle that.
Other solutions are still welcome :-)

Related

TYPO3: Backend Layout Condition in TypoScript

I'd like to change the way elements are rendered depending on the page's backend layout.
Changing the fluid styled content template depending on the backend layout works as following:
[globalVar = TSFE:page|backend_layout = 1][globalVar = TSFE:page|backend_layout = 2]
lib.fluidContent.templateRootPaths.10 = EXT:ds_res/Resources/Private/Templates/ContentTemplates/
[global]
If it's 1 or 2, then use the other templates.
However, this only works if the BE layout is set directly at the page and not when it's inherited from its parent.
How to fix this?
Running TYPO3 7.6.15
In TYPO3 7.5 "Backend Layout"-Conditions has been simplified with "pagelayout" in Typoscript. Example:
page.10 = FLUIDTEMPLATE
page.10 {
file.stdWrap.cObject = CASE
file.stdWrap.cObject {
key.data = pagelayout
default = TEXT
default.value = EXT:sitepackage/Resources/Private/Templates/Home.html
3 = TEXT
3.value = EXT:sitepackage/Resources/Private/Templates/1-col.html
4 = TEXT
4.value = EXT:sitepackage/Resources/Private/Templates/2-col.html
}
}
Instead of:
field = backend_layout
field.data = levelfield:-2,backend_layout_next_level,slide
field.ifEmpty = default
Maybe this also works in your conditions like this:
[globalVar = TSFE:page|pagelayout = 1]
However, you should not change the used template file with [xy]-conditions and prefer using a CASE shown in the example above. Each number is the UID of a backend_layout by the way.
In TYPO3 9.5+ you can use typoscript conditions like:
[page["backend_layout"] == 'pagets__2']
page.bodyTagCObject.value.wrap = <body id="uid|" class="fullpage">
[end]
Edit:
As Bernd has mentioned use backend_layout only if you need the real defined field. If you need the computed value (e.g. for a sub page getting its layout from the backend_layout_next_level from a parent page) use pagelayout with a case like:
bodyTagCObject = TEXT
bodyTagCObject.value.field = uid
bodyTagCObject.value.wrap.cObject = CASE
bodyTagCObject.value.wrap.cObject{
key.data = pagelayout
default = TEXT
default.value = <body id="uid|" class="standard">
pagets__2 = TEXT
pagets__2.value = <body id="uid|" class="fullpage">
}
We use this solution
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
templateName = TEXT
templateName.stdWrap {
cObject = TEXT
cObject {
data = levelfield:-2,backend_layout_next_level,slide
override.field = backend_layout
split {
token = pagets__
1.current = 1
1.wrap = |
}
}
ifEmpty = Index
}
layoutRootPaths {
10 = EXT:yourext/Resources/Private/Layouts
}
partialRootPaths {
10 = EXT:yourext/Resources/Private/Partials
}
templateRootPaths {
10 = EXT:yourext/Resources/Private/Templates
}
}
This approach is when u do not have the Backendlayouts in the DB (made through the backend) but include them from files. As there is no uid then you go by the templatename.
Example:
If you use this PageTS:
mod.web_layout.BackendLayouts {
Blankpage {
title = Blankpage
name = Blankpage
icon = EXT:yourext/Resources/Public/Icons/BackendLayouts/Blankpage.jpg
config {
backend_layout {
colCount = 1
rowCount = 2
rows {
1 {
columns {
1 {
name = Nameofthecolumn
colPos = 0
colspan = 1
}
}
}
2 {
columns {
1 {
name = Nameofthesecondcolumn
colPos = 1
colspan = 1
}
}
}
}
}
}
}
You will need a Template.html with the name Blankpage.html within your EXT-Templates.
So you can add more Templates and Backendlayouts without touching the TS again. Simply add PageTS and a html-template.
There is a feature available which avoids having that code duplicated
page.10 = FLUIDTEMPLATE
page.10 {
templateName = TEXT
templateName.stdWrap.cObject = CASE
templateName.stdWrap.cObject {
key.data = pagelayout
....
As you can not handle the inherited layouts in conditions you need to use typoscript. My solution is this:
page.10 = FLUIDTEMPLATE
page.10 {
templateRootPaths.1 = {$resDir}/Private/Templates
partialRootPaths.1 = {$resDir}/Private/Partials
layoutRootPaths.1 = {$resDir}/Private/Layouts
templateName = TEXT
templateName.cObject = CASE
templateName.cObject {
key.data = levelfield:-1, backend_layout_next_level, slide
key.override.field = backend_layout
#Default Template
default = TEXT
default.value = subpage
# homepage
pagets__homepage = TEXT
pagets__homepage.value = homepage
pagets__subpage = TEXT
pagets__subpage.value = subpage
}
variables {
:
pageLayout = TEXT
pageLayout.data = levelfield:-1, backend_layout_next_level, slide
pageLayout.override.field = backend_layout
// since TYPO3 7 this already is computed by the core and this gives the same:
pageLayout = TEXT
pageLayout.data = pagelayout
:
}
}
Avoid using file for better implementation with ..RootPaths.
As we use backendlayouts defined in files (which gets included in the pageTSconfig) the key names starting with pagets__, you also might use the numbers of backend_layout records.
I use the constant {$resDir} to define the root of resources which can be changed in an easy way. In a siteextension this could be:
resDir = EXT:site_project1/Resources
I also define a fluid variable with the currently active page layout for further differentiation in the templates.
If you want the ...RootPaths to be different for each layout you need to build cObject with a CASE obejct similar to my selection of the template name.
In general: all this could be handled in the fluid templates if you have the backend layout available in your variables: you only need to have one starting template, which calls a layout where all further calls to partials are individualized by the current layout like
<f:render partial="{pageLayout}/header" arguments="{_all}" />
TYPO3 11.x:
[tree.pagelayout == 2]
...
[global]
https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.0/Feature-88276-TypoScriptConditionForPageLayout.html

TYPO3 7.4 display categories

I'm trying to display the categories of the current page.
Because I'm not that good in TYPO3, I first tried displaying all the categories before trying to display the current one.
The following snippet somehow doesn't work.
lib.categorized_content = RECORDS
lib.categorized_content {
categories.field = selected_categories
categories.relation.field = category_field
tables = tt_content
conf.tt_content = TEXT
conf.tt_content {
stdWrap.field = header
stdWrap.typolink.parameter = {field:pid}
stdWrap.typolink.parameter.insertData = 1
stdWrap.wrap = <li>|</li>
}
wrap = <ul>|</ul>
}
This is where I got this snippet from: https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Records/Index.html#categories
I'm using <f:cObject typoscriptObjectPath="lib.categorized_content" /> to implement it into my template.
Can someone help?
selected_categories and category_field are flexform field (as you can see from the suffix .field of the configuration property) from the Special Menu content element.
You have to replace those with the actual value.

how to use load_register in typo3

I begin with TYPO3 and I try to work with LOAD_REGISTER.
I've read multiple examples on the net and I want to try some tests but I'm not able to output the data from LOAD_REGISTER-variables.
Here's my code :
page = PAGE
page {
count = LOAD_REGISTER
count {
nbblocks.cObject = TEXT
nbblocks.cObject {
data = patate
}
}
10 = TEXT
10.value = register:nbblocks
10.wrap = <h1>|</h1>
}
Page only shows "register:nbblocks", which must be a basic mistake.
Thanks in advance for the help :-)
There are several problems with your code.
Firstly, the page.count = LOAD_REGISTER content object is not run before page.10 = TEXT, which means that the register you're creating is does not exist where you want to use it. This can be fixed by renaming page.count to page.10 and page.10 to page.20.
Secondly, you should set the value-key on nnblocks.cObject instead of the data-key.
Thirdly, you need to wrap registers used in the value-property of the TEXT-object in curly brackets ({register:nbblocks}), and lastly, you need to set stdWrap.insertData = 1 on the TEXT-object.
All in all, this gives you the following code:
page = PAGE
page {
10 = LOAD_REGISTER
10 {
nbblocks.cObject = TEXT
nbblocks.cObject {
value = patate
}
}
20 = TEXT
20.value = {register:nbblocks}
20.wrap = <h1>|</h1>
20.stdWrap.insertData = 1
}

TYPO3 TypoScript: Display a list of subpages with content on parent page

I am trying to create an archive page that displays a list of subpages, similar to WordPress but display the parent's subpages instead of posts. I want the archive page to include the following from the subpage:
Title
First image
First 150 words of regular text element
At the moment I can display a page title, but that's where I got stuck. I am placing the code in a sub template. Here is the code.
lib.portfoliolist = CONTENT
lib.portfoliolist.table = pages
lib.portfoliolist.select {
pidInList = this
}
lib.portfoliolist.renderObj = COA
lib.portfoliolist.renderObj {
stdWrap.wrap = <div class="project">|</div><hr />
10 = TEXT
10 {
field = title
wrap = <h2>|</h2>
10.typolink.parameter.field = uid
}
}
If it helps, all of the images are within the fileadmin/user_upload/ directory, and this is my page structure:
Root
Home
About
Project Portfolio
Project 1
Project 2
Blog
Contact Us
Seems like I figured it out myself, all I had to do was call for content in a separate query. For those that are looking to achieve something similar, here is the code I used to help you out.
lib.portfoliolist = CONTENT
lib.portfoliolist.table = pages
lib.portfoliolist.select {
orderBy = sorting ASC
}
lib.portfoliolist.renderObj = COA
lib.portfoliolist.renderObj {
stdWrap.allWrap = <div class="row">|</div>
stdWrap.wrap = <div class="project col-lg-6 col-md-6 col-sm-12 col-xs-12">|</div>
10 = TEXT
10 {
field = title
wrap = <h2>|</h2>
typolink.parameter.field = pages.uid
}
20 = CONTENT
20 {
table = tt_content
select {
pidInList.field = uid
selectFields = header, bodytext
orderBy = sorting ASC
}
renderObj = COA
renderObj {
30 = TEXT
30.value {
field = bodytext
wrap = <div>|</div>
}
}
}
}

Get rid of "csc-frame" div wrap in TYPO3

Here is my code:
lib.navigation{
10 = RECORDS
10 {
source = uid
tables = tt_content
}
}
Here I'm just creating a menu through content element and I wanted to remove the default div with class=csc-frame csc-frame-frame1 from the rendered content
I used like this:
lib.navigation{
10 = RECORDS
10 {
conf.tt_content.stdWrap.innerWrap.cObject.default = TEXT
source = uid
tables = tt_content
}
}
but this will remove only csc_default div.
This might do the trick. Make sure to include it before the navigation definition.
tt_content.stdWrap.innerWrap.cObject.default >