I was using fluidpages for template building, and would like to choose the template dynamically based on a field in the fe_users table. For example, most people will see the EXT:default template by default, while some will see EXT:advanced template instead, as they are marked as special.
I tried
plugin.tx_template {
view {
templateRootPaths {
0 = EXT:default/Resources/Private/Templates/
10 {
data = TSFE:fe_user|user|template
wrap = EXT: | /Resources/Private/Templates/
}
}
}
}
But it seems the TS is not parsed and is used directly by fluid, therefore failed.
Any idea or hint is appreciated!
Actually this may be possible. But i can't see an obvious way on how to override the chosen template in the page properties.
To my knowledge, you are required to select a template in the page record.
If you find a possibility to override that one, you could use a TS Setup like this:
EXT:template_package/Configuration/TypoScript/constants.txt:
plugin.tx_templatepackage {
view {
templateRootPaths.default = EXT:template_package/Resources/Private/Templates/
partialRootPaths.default = EXT:template_package/Resources/Private/Partials/
layoutRootPaths.default = EXT:template_package/Resources/Private/Layouts/
}
}
EXT:template_package/Configuration/TypoScript/setup.txt:
plugin.tx_templatepackage {
view {
templateRootPaths.default = {$plugin.tx_templatepackage.view.templateRootPaths.default}
partialRootPaths.default = {$plugin.tx_templatepackage.view.partialRootPaths.default}
layoutRootPaths.default = {$plugin.tx_templatepackage.view.layoutRootPaths.default}
}
}
Above part will setup your global paths.
After that, you'll define your sub packages for templates.
EXT:template_package/Configuration/TypoScript/Basic/setup.txt
plugin.tx_templatepackage {
view {
templateRootPaths.10 = {$plugin.tx_templatepackage.view.templateRootPaths.0}Basic/
partialRootPaths.10 = {$plugin.tx_templatepackage.view.partialRootPaths.0}Basic/
layoutRootPaths.10 = {$plugin.tx_templatepackage.view.layoutRootPaths.0}Basic/
}
}
And
EXT:template_package/Configuration/TypoScript/Advanced/setup.txt
plugin.tx_templatepackage {
view {
templateRootPaths.20 = {$plugin.tx_templatepackage.view.templateRootPaths.0}Advanced/
partialRootPaths.20 = {$plugin.tx_templatepackage.view.partialRootPaths.0}Advanced/
layoutRootPaths.20 = {$plugin.tx_templatepackage.view.layoutRootPaths.0}Advanced/
}
}
Of course you should make them available within TYPO3:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Template Package: Base');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript/Basic', 'Template Package: Basic');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript/Advanced', 'Template Package: Advanced');
After all of that, you could override a value — IDK which one — via:
[usergroup = group1-uid]
// override option, which defines the default template
[usergroup = group2-uid]
// override option, which defines the default template
Sorry I can't help you out any further. I tried to dig deeper into EXT:flux and EXT:fluidpages. But i can't see that option.
Related
I'm using a Typo3 website version 10 and the sitemap is not working properly,
i can see the configuration in the typoscript object browser but in the front-end www.mydomain.ch/?type=1533906435 the xml file is blanc.
Frontend screenshot:
Typoscript object browser screenshot:
seo extension is installed.
the website is multilangage.
what can be missing so that i see the sitemap ?
If this is all you have, then you are missing some key configuration. You need to specify what should be shown. So, on your TypoScript, based on the documentation, you should define what pages/extension etc must be shown. For example:
plugin.tx_seo {
config {
xmlSitemap {
sitemaps {
pages {
config {
excludedDoktypes = 137, 138
additionalWhere = AND (no_index = 0 OR no_follow = 0)
#rootPage = <optionally specify a different root page. (default: rootPageId from site configuration)>
}
}
}
}
}
}
Here is an example for the extension news as well, in case you are using it.
plugin.tx_seo.config {
xmlSitemap {
sitemaps {
news {
provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider
config {
table = tx_news_domain_model_news
additionalWhere =
sortField = sorting
lastModifiedField = tstamp
changeFreqField = sitemap_changefreq
priorityField = sitemap_priority
pid = 26
recursive = 2
url {
pageId = 25
fieldToParameterMap {
uid = tx_news_pi1[news]
}
additionalGetParameters {
tx_news_pi1.controller = News
tx_news_pi1.action = detail
}
}
}
}
}
}
}
Here the documentation as well: Documentation
i have solved the problem, i think it was the sourceopt extension installed have a bug, i have update it to the latest version, now i can see the xml sitemap working fine, thanks!
The way to add a DataProcessor to a PAGE or a FLUIDTEMPLATE is often shown. How can it be assigned to a TYPO3 plugin?
For a PAGE you can do it like this:
page {
10 {
dataProcessing {
1558428437 = BK2K\BootstrapPackage\DataProcessing\ConstantsProcessor
1558428437 {
as = myconstants
key = settings.constants
}
}
}
}
But can you do something like this:
config.tx_extbase {
dataProcessing {
1558428437 = BK2K\BootstrapPackage\DataProcessing\ConstantsProcessor
1558428437 {
as = myconstants
key = settings.constants
}
}
Many thanks!
No, this is not possible since data processors is a feature of the FLUIDTEMPLATE content object alone.
In this case you can invoke the ConstantsProcessor manually in your controller action. You can get the current ContentObjectRenderer via $this->configurationManager->getContentObject(). The $processorConfiguration is the same as in TypoScript but as array:
$constantsProcessor = GeneralUtility::makeInstance(ConstantsProcessor::class);
$data = $constantsProcessor->process(
$this->configurationManager->getContentObject(),
[],
[
'key' => 'settings.constants',
'as' => 'myconstants',
],
[]
);
// Use $data['myconstants']
That's currently not possible.
This would definitely be a feature that would make live of Integrators much easier.
After a "long way" with Google, Searching and many tries:
I created a lib.variable for the current Page:
lib.currentPage = TEXT
lib.currentPage.data = page:uid
If I debug it in my FluidTemplate in the Frontend with:
Testing currentPage: <f:cObject typoscriptObjectPath="lib.currentPage" />
I got the correct value.
Now I want to use that Variable in a Condition in my pageSetup.ts like follows:
[DB:pages:lib.currentPage:backend_layout = pagets__pagelayout_logoclaim_subpage]
page.includeJSFooter.belayoutlogoclaim = EXT:rm_base/Resources/Public/JS/be_logoclaim.js
[end]
I testet this with some other Conditions, but nothing works like expected.
Tested Conditions:
[page|backend_layout = pagelayout_logoclaim_subpage]
[globalVar = TSFE:page|backend_layout = pagelayout_logoclaim_subpage]
I also tested the Condition in the TypoScript Object Browser, and here it looks like good working:
TypoScript Object Browser - If I activate the Condition
SourceCode in the Frontend on a Site with the correct PageLayout
I need this, because I have two different Menus, and they need different JavaScripts, to avoid wrong behaviour in the Frontend.
Update:
I inserted the pageLayouts like this:
page = PAGE
page {
10 = FLUIDTEMPLATE
10 {
partialRootPath = EXT:rm_base/Resources/Private/Templates/Fluid/Partials/
layoutRootPath = EXT:rm_base/Resources/Private/Templates/Fluid/Layouts/
file.stdWrap.cObject = CASE
file.stdWrap.cObject {
key.data = pagelayout
// Default-Template is LogoFull_Subpage (No Navigation Dependence)
default = TEXT
default.value = EXT:rm_base/Resources/Private/Templates/Fluid/LogoFull_Subpage.html
// LogoClaim - Subpage
pagets__pagelayout_logoclaim_subpage = TEXT
pagets__pagelayout_logoclaim_subpage.value = EXT:rm_base/Resources/Private/Templates/Fluid/LogoClaim_Subpage.html
}
}
You see: The Backendlayouts are in Files of my Extension, not in the Database-Table: backend_layouts.
Update 2:
I would prefer a TypoScript-Way, if someone knows how - with external BE-Layouts. Thank you.
As I've seen the prefix pagets__ ,I guess that the problem here is that the backend_layouts are not stored in the database, so I think that a condition about that would not work.
If you are using a different html template for each backend layout and you are running TYPO3 8.7.x there is a different way to solve this issue: Add to your template file a new section called:
<f:section name="FooterAssets">
<!--your code here-->
</f:section>
This section will be loaded just before the closing of </body>. As far as I remember you don't even have to call this section in your layout file.
i would opt for using the VHS extension which provides an asset viewhelper.
you than include the asset view helper into the frontend template you are rendering. and it takes care about plaching the javascript in the header / footer
it allows also to definde dependancies and loads the script in the correct order. also supports concatination / minification ...
an example include might look like this:
<v:asset.script path="EXT:your_ext/Resources/Public/JavaScript/menu_a.js" dependencies="jquery" />
this requires you that you specified "jquery" via typoscript (or another assit view helper)
example typoscript:
plugin.tx_vhs.settings.asset.jquery {
path = EXT:your_ext/Resources/Public/JavaScript/jquery.js
type = js
}
I found another solution, that uses a TypoScript Custom Condition:
First I create a BackendlayoutCondition.php in my Extension here:
/Classes/TypoScript/BackendlayoutCondition.php
Its content is this (See Comments for more Detail):
<?php
namespace RM\RmBase\TypoScript;
use \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractCondition;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;;
class BackendlayoutCondition extends AbstractCondition
{
/**
* Evaluate condition
*
* #param array $conditionParameters
* #return bool
*/
public function matchCondition(array $conditionParameters)
{
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($conditionParameters,'cond Params');
# Return false if in Backend (Condition for Frontend only)
if (!$GLOBALS['TSFE']) return false;
# QueryBuilder for Table: pages
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
# Check if current BackendLayout is inside the $conditionParameters
if (!empty($conditionParameters) && substr($conditionParameters[0], 0, 1) === '=') {
# Trim the Parameter to get the correct Value of the Parameter (behind '=')
$conditionParameters[0] = trim(substr($conditionParameters[0], 1));
# Get Backendlayout on this Page
$backendLayoutOnThisPage = $queryBuilder
->select('backend_layout')
->from('pages')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(intval($GLOBALS['TSFE']->id), \PDO::PARAM_INT))
)
->execute();
# Store Backendlayout Value of the current Page in $backendLayoutOnThisPage
$backendLayoutOnThisPage = $backendLayoutOnThisPage->fetch()['backend_layout'];
} else {
# If no ConditionParameter was set return false
return false;
}
# Check if parent BackendLayout_NextLevel is inside the $conditionParameters
if ($backendLayoutOnThisPage == '') {
# Get pageRepository
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$pageRepository = $objectManager->get('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
# Get Rootline of the current Page
$pageRootline = $pageRepository->getRootLine(intval($GLOBALS['TSFE']->id));
# Set rootlineIndex to the Parent Page Index
$rootlineIndex = count($pageRootline)-2;
# Check Parent Page Backendlayout_NextLevel till 0 or Backendlayout found
while ($rootlineIndex > 0) {
if ($pageRootline[$rootlineIndex]['backend_layout_next_level'] == $conditionParameters[0]) {
return true;
} else {
$rootlineIndex--;
}
}
# No BackendLayout_NextLevel found till 0
return false;
} else {
# If Condition Backendlayout found return true, otherwise return false
if ($backendLayoutOnThisPage == $conditionParameters[0]) {
return true;
} else {
return false;
}
}
}
}
(Edited 2)
Than I just have to use the following Condition in my pageSetup.ts:
[RM\RmBase\TypoScript\BackendlayoutCondition = pagelayout_logoclaim_subpage]
page.includeJSFooter.belayoutlogoclaim = EXT:rm_base/Resources/Public/JS/be_logoclaim.js
[global]
Now I have this Sourcecode in the Frontend:
<script src="/typo3conf/ext/rm_base/Resources/Public/JS/be_logoclaim.js?1523005944" type="text/javascript"></script>
not that:
<script src="/typo3conf/ext/rm_base/Resources/Public/JS/be_logoclaim.js" type="text/javascript"></script>
if I use the FooterAssets method:
<f:section name="FooterAssets">
<script src="/typo3conf/ext/rm_base/Resources/Public/JS/be_logoclaim.js" type="text/javascript"></script>
</f:section>
Edit: I found some errors in my Answer, i fix it and edit my answer then.
Edit2: Now the Condition checks the Backendlayouts and the Backendlayouts_Nextlevel Fields for Backendlayouts to get all possible BE-Layouts including the inherited.
The problem with the backend_layout field is that there also is a field backend_layout_next_level which affects subpages. so you can't build a simple condition.
Either you use stdWrap.if where you can calculate the current value for backend_layout overlaying an inherited value from backend_layout_next_level.
Or you define a userfunc where you evaluate it yourself in PHP.
Be aware that layouts defined in records have another prefix than layouts defined in pagesTS.
edit:
Example
temp.layout = CASE
temp.layout {
key.data = levelfield:-1, backend_layout_next_level, slide
key.override.field = backend_layout
default = TEXT
default.value = default-layout
1 = TEXT
1.value = layoutdefinition_from_record
pagets__layout2 = TEXT
pagets__layout2.value = layoutdefinition_from_pageTSconfig
sitepackage__layout3 = TEXT
sitepackage__layout3.value = layoutdefinition_from_sitepackage
}
Now you can use temp.layout for further decisions:
10 = TEXT
10.field = bodytext
10.wrap = <div class="demo">|</div>
10.wrap.if {
equals.cObject < temp.layout
value = default-layout
}
I'm trying to extend the fluid_styled_content element "Menu". Within my partial (e.g. typo3conf/ext/my_theme/Resources/Private/Templates/Content/Partials/Menu/Type-1.html I need to access the page properties of the page where the menu CE resides. How can I archive this? {data} contains only the data of the content element.
In {data.pid} you have the uid of the page.
You can use a viewhelper to get the complete pages record (in ext:vhs there is a viewhelper to get any kind of records).
or you can use <f:cObject> and some typoscript to access single values.
Use \TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor.
I cannot check the code right now but you could take this as a starting point:
tt_content.menu.dataProcessing {
30 = \TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
30 {
table = pages
where.dataWrap = uid = {TSFE:id}
as = page
}
}
Afterwards you can access the current page‘s properties via {page.0.property}.
There‘s just one query for each menu content object with this approach while most view helper solutions tend to increase the number of database queries issued.
#undko: The DatabaseQueryProcessor was the perfect hint. But your snippet had two problems I had to fix:
- the TypoScript code needs pidInList to work
- in the Fluid Template there was data missing: pageproperties.0.data.myproperty
Here is my final code that works fine for me:
tt_content.menu.dataProcessing {
30 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
30 {
table = pages
where.dataWrap = uid = {TSFE:id}
pidInList = 1
as = pageproperties
}
}
In the Fluid template I use {pageproperties.0.data.tx_mytheme_fieldname}.
I don't know why exactly but I can't access page properties with the proposed solution. I'm using Typo3 10.4.9.
I found an alternative solution :
tt_content.menu dataProcessing {
30 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
30 {
table = pages
pidInList = 0
recursive = 99
uidInList = this
as = pageproperties
}
}
Maybe this will help someone else.
More brutal approach; to access the page properties everywhere, for example in a custom content element. Create in the sitepackage Classes/ViewHelper/GetPagePropertiesViewHelper.php :
<?php namespace Xxx\Sitepackage\ViewHelpers;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class GetPagePropertiesViewHelper extends \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper
{
public function initializeArguments()
{
$this->registerArgument('pid', 'int', 'The page uid to get the pageproperties from', true, 1);
$this->registerArgument('property', 'string', 'A specific page property to be returned', false, null);
}
public function render()
{
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable('pages');
$pageProperties = [];
$statement = $queryBuilder
->select('*')
->from('pages')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($this->arguments['pid'], \PDO::PARAM_INT))
)
->execute();
while ($row = $statement->fetch()) {
$pageProperties[] = $row;
}
if ($property) {
return $pageProperties[0][$property];
}
return $pageProperties[0];
}
}
Usage in a template or partial:
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:c="http://typo3.org/ns/Xxx/Sitepackage/ViewHelpers"
data-namespace-typo3-fluid="true">
<c:getPageProperties pid="{data.pid}" property="description"/>
<f:debug><c:getPageProperties pid="{data.pid}"/></f:debug>
I am using a custom plugin and I need to add the page title as one of the plugin's settings variables:
plugin.tx_fsearch {
settings {
resultsPath = search-results/brand/{field:title}/make/{field:title}
resultsPath.insertData = 1
}
}
However this is outputting the word 'Array' instead of the path I need.
Does anyone know how I might be able to make this work?
There is no stdWrap available for settings in extbase extensions, no matter if using TEXT cObj or insertData!
As a workaround, you can fix that yourself by doing something like EXT:news does here https://github.com/georgringer/news/blob/master/Classes/Controller/NewsController.php#L495
public function injectConfigurationManager(
\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
) {
$this->configurationManager = $configurationManager;
$typoScriptService = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Service\TypoScriptService::class);
$typoScriptArray = $typoScriptService->convertPlainArrayToTypoScriptArray($originalSettings);
$stdWrapProperties = GeneralUtility::trimExplode(',', $originalSettings['useStdWrap'], true);
foreach ($stdWrapProperties as $key) {
if (is_array($typoScriptArray[$key . '.'])) {
$originalSettings[$key] = $this->configurationManager->getContentObject()->stdWrap(
$originalSettings[$key],
$typoScriptArray[$key . '.']
);
}
}
}
$this->settings = $originalSettings;
}
Or you skip the TS part and call the stdWrap directly in your controller.
Try TEXT object
plugin.tx_fsearch {
settings {
resultsPath = TEXT
resultsPath.value = search-results/brand/{field.title}/make/{field.title}
}
}