TYPO3 issue with Typoscript and accessing $this->settings - php

I'm using TYPO3 version 7.6.14 and I've created an extension for client which has four controllers, four plugins and its pretty big overall. Anyway now I'm required to add option (settings variable) for dynamic or user selected "page id" which is then used to redirect from one plugin to another. There might be better solution for my problem but I'm trying to do something like:
plugin.tx_extname_basket {
view {
# cat=plugin.tx_extname_basket/file; type=string; label=Path to template root (FE)
templateRootPath = EXT:extname/Resources/Private/Templates/
# cat=plugin.tx_extname_basket/file; type=string; label=Path to template partials (FE)
partialRootPath = EXT:extname/Resources/Private/Partials/
# cat=plugin.tx_extname_basket/file; type=string; label=Path to template layouts (FE)
layoutRootPath = EXT:extname/Resources/Private/Layouts/
}
persistence {
# cat=plugin.tx_extname_basket//a; type=string; label=Default storage PID
#storagePid =
}
settings {
# cat=plugin.tx_extname_basket//a; type=int; label=Products Page ID
productsPage =
}
}
Now the problem is that even though I am 100% sure Typoscript is properly included into page where extension is loaded, the variables $this->settings['productsPage'] and in FLUID {settings.productsPage} doesn't work. I cleared whole cache and even tried removing whole typo3temp folder and it still doesn't work. I also tried debugging $this object and it says settings => NULL.
Oh the productsPage is entered in Default Root template under "SETUP" and when browsing Typoscript objects (in administration) I can see the setting set just fine. So I don't think I have invalid TypoScript.

If you have four plugins you have to set this Typoscript settings for each plugin. If your Typoscript above is included correctly, "settings" will only be accessible for the plugin "basket".
Another thing: The comments in your Typoscript seems like those settings are Typoscript constants and not Typoscript setup. In the setup you have to pass those constants to the plugin configuration too. Example:
plugin.tx_extname_basket {
settings {
productsPage = {$plugin.tx_extname_basket.settings.productsPage}
}
}
You also have to pass the other constants for templates etc. to the setup.

Related

Dynamically resolvable Twig namespaces

I have a Symfony application that handles request from multiple domains. On these domains, customers have the ability to create custom Twig templates that can be used in their CMS module. These templates are saved to a /path/to/ftp/example.com/cms_templates/ directory.
In previous versions of Symfony, rendering these templates was not an issue. On an incoming request on mydomain.com/page_one, the absolute path of the Twig template could be resolved to e.g. /path/to/ftp/mydomain.com/cms_templates/page_one.html.twig. The existence of the template was verified and the template was rendered. However, in Symfony 4 support for absolute template paths has been removed.
I thought of registering an extra Twig namespace in twig.paths called 'custom' that points to /path/to/ftp and then reference the templates with #custom/mydomain.com/cms_templates/page_one.html.twig. The problem is, /path/to/ftp contains not only templates but loads and loads of other files too. And the TemplateCacheWarmer is looping through all of these files.
What I'am actually looking for is a way to register a Twig namespace, say #cms that is resolved on the fly such that I can inject the hostname of the current request in it. I would then be able to reference a template using #cms\page_one.html.twig. Cache warmup isn't necessary for these templates.
How to achieve such functionality? I looked ad the Twig documentation but it looks like I just can't figure it out.
TLDR; How to get Symfony/Twig to resolve the template #foo\template.html.twig to /path/to/domain.com/templates/template.html.twig when domain.com differs between requests.
One solution would be to prepend configuration
public function prepend(ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');
if (isset($bundles['TwigBundle'])) {
$config = $container->getExtensionConfig('twig')[0];
$paths = ['/path/to/cms' => 'cms'];
if (array_key_exists('path', $config)) {
$paths = array_merge($config['paths'], $paths);
}
$config['paths'] = $paths;
$container->prependExtensionConfig('twig', $config);
}
}
The problem would be this:
If you are building some kind of CMS - then this would mean - no other bundle/module/plugin could ever register additional twig namespaces again - if I am right.
So... I am interested in other solutions if there are some.

How do i tell my TYPO3 which setup.txt to use?

Having installed the introduction_package and with it the bootrstrap_package, I need to work in a different directory then the bootstrap_package which setup.txt is being used.
What ways are there, so my setup knows which one to use.
I hope this make sense...
You have multiple options to include typoscript.
aside from any extension typoscript ('static templates') you need a template in your root page. Here you can include static templates from extensions and also define your individual part of typoscript.
Be aware: some extensions include their static templates uncondinioally global (you might remove their typoscript).
if you use a site-package you will provide your own typoscript templates (maybe your own setup.txt)

Running two versions of a site from same Yii code

I have two versions of my project. For one i use a different CSS and index page and for another i use different. Rest of the things that is controller, models and components are same. The only difference is in view(one or two files) and CSS.
Is there any way to manage this? Like when the URL is URL1 then use CSS1/View1 folder and when url is URL# use CSS2/view2 folder. I have gone through the modules section of Yii but i don't think they are what i need here.
So now I started to use themes. My folder structure is like:
WebRoot
- assests
- css
- images
- protected
- themes
- theme1
-views
-site
-layout
-template
- theme1
-theme2
-views
-site
-layout
-template
In my controller I have done this:
public function init() {
if (SITE_TITLE == 'xxxxx')
Yii::app()->theme = 'theme1';
else
Yii::app()->theme = 'theme2';
parent::init();
}
Which sets theme correctly. but i keep getting file not found as renderer is looking in protected.
I think, you need use themes. Here is documentation: http://www.yiiframework.com/doc/guide/1.1/en/topics.theming
UPDATED after discussion
Trouble in ETwigViewRenderer and it working with themes
If you want to change entire layout, perhaps this is a good way to do:
Setting Layout in Yii
In case you want only to change css they why don't you rely on request uri or domain name?
Yii::app()->getBaseUrl(true)

TYPO3 Extbase backend module. Template path issue

I'm experiencing a strange problem with extbase/fluid extension creation.
I use TYPO3 6.1
I've made an extension with a backend module on my dev server (same configuration/hardware then the prod). The module works perfectly with the path to the template :
myext/Resources/Private/Backend/Templates
myext/Resources/Private/Backend/Layouts
myext/Resources/Private/Backend/Partials
After this, I downloaded my extension's zip in the ext manager and then installer on the prod server. Now I can't use my extension because the module don't find the templates.
I've configured the extension by the same way. The templates are in the right path.
I test to move my folder to the parent level :
myext/Resources/Private/Templates
myext/Resources/Private/Layouts
myext/Resources/Private/Partials
With this it works, but in the module configuration, I specify the right path to the "Backend/" folder.
I wont to move my folder in the Private folder, I want it to run in the Private/Backend folder.
I've included the extension static template to the website root TS template.
Here's the constants :
module.tx_myext {
view {
# cat=module.tx_myext/file; type=string; label=Path to template root (BE)
templateRootPath = EXT:wng_myext/Resources/Private/Backend/Templates/
# cat=module.tx_myext/file; type=string; label=Path to template partials (BE)
partialRootPath = EXT:wng_myext/Resources/Private/Backend/Partials/
# cat=module.tx_myext/file; type=string; label=Path to template layouts (BE)
layoutRootPath = EXT:wng_myext/Resources/Private/Backend/Layouts/
}
persistence {
# cat=module.tx_myext//a; type=string; label=Default storage PID
storagePid =
}
}
And here's the setup :
module.tx_myext {
persistence {
storagePid = {$module.tx_myext.persistence.storagePid}
}
view {
templateRootPath = {$module.tx_myext.view.templateRootPath}
partialRootPath = {$module.tx_myext.view.partialRootPath}
layoutRootPath = {$module.tx_myext.view.layoutRootPath}
}
}
The main problem will be that the typoscript configurations will not get loaded on storage folders or pages without an template in the root path.
Explaination:
typoscript configuration you will set for your extension wether it is in ext_typoscript_setup, an static template or via php it will always need an system record template somewhere in the root of the page. otherwise it will not get rendered - and no path settings for your extbase extensions will happen, so the default layout, template and partial path is set and thats the place the script will look for your stuff.
Default is:
/Private/Resources/Layout/
/Private/Resources/Partials/
/Private/Resources/Templates/#Controllername/#Actionname
if you need to override these for your backendmodule you can work around that problem by injecting the settings for the view directly in your controller.
<?php
namespace VendorKey\ExtensionName\Controller;
class SettingsController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* Initializes the controller before invoking an action method.
* #return void
*/
protected function initializeAction() {
$this->setBackendModuleTemplates();
}
/**
* Set Backend Module Templates
* #return void
*/
private function setBackendModuleTemplates(){
$frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$viewConfiguration = array(
'view' => array(
'templateRootPath' => 'EXT:extension_name/Resources/Private/Templates/Modules/',
'partialRootPath' => 'EXT:extension_name/Resources/Private/Partials/Modules/',
'layoutRootPath' => 'EXT:extension_name/Resources/Private/Layouts/Modules/',
)
);
$this->configurationManager->setConfiguration(array_merge($frameworkConfiguration, $viewConfiguration));
}
/**
* action settings
* #return void
*/
public function settingsAction(){
}
}
i hope this helps
greetz benji
As #benjamin-kott explains, TYPO3's backend modules configurations need to be loaded first. Unfortunately, extension's typoscript files are not automatically loaded by default.
One way of make TYPO3 aware of this typoscript files is creating two files in extension's root folder:
ext_typoscript_constants.txt
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:myext/Configuration/TypoScript/constants.txt">
ext_typoscript_setup.txt
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:myext/Configuration/TypoScript/setup.txt">
(kind of obvious but: you should replace this paths with yours)
After adding this files, you should reinstall the extension to see changes. You can use the TypoScript Object Browser to find out if your setup and constants are being loaded.
Try to clean all caches, even in typo3temp/Core/Cache (or something like that)
I dont realy know ur setup, but normaly you must setup these paths in /Configuration/TypoScript/setup.txt like this
module.tx_yourext {
persistence {
storagePid = {$pid}
}
view {
templateRootPath = {$templateRootPath}
partialRootPath = {$partialRootPath}
layoutRootPath = {$layoutRootPath}
}
}
This configuration does not being used until you add the static template of your extension. Also you should add these lines to the ext_tables.php
if (TYPO3_MODE === 'BE') {
Tx_Extbase_Utility_Extension::registerModule(
$_EXTKEY,
'web', // Main area
'mod1', // Name of the module
'', // Position of the module
array( // Allowed controller action combinations
'Controller' => 'actionName'
),
array( // Additional configuration
'access' => 'user,group',
'icon' => 'EXT:my_ext/ext_icon.gif',
'labels' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_mod.xml',
)
);
}
Although this thread is quite old I want to show you guys my solution for TYPO3 7.6 LTS.
First you need to include your TypoScript files via Template > Edit whole record > Includes.
And in your TypoScript you need to use templateRootPaths.0 instead of templateRootPath:
module.tx_extension {
view {
templateRootPaths.0 = EXT:extension/Resources/Private/Backend/Templates/
partialRootPaths.0 = EXT:extension/Resources/Private/Backend/Partials/
layoutRootPaths.0 = EXT:extension/Resources/Private/Backend/Layouts/
}
}

Where can i save my block in cakephp directory structure that will contain all my menu links?

I want to create my custom theme in CakePHP. Where can I save my block in CakePHP directory structure that will contain all my menu links? And how can I fetch the file from View\Themed\MyTheme\Layouts\default.ctp?
Either use Elements (if your navbar shows on every single view) or use View Blocks (if navbar only shows on some views).
In your default.ctp file you would just do..
echo $this->element('navbar');
Which would render Views/Elements/navbar.ctp onto Views/Layouts/default.ctp (if you are using the default layout).
To access: View\Themed\MyTheme\Layouts\default.ctp, in (Cake 2.1+), you must tell cake which theme you want to use like so:
public $theme = 'MyTheme';
// or override in an action:
$this->theme = 'MyTheme';
Then:
$this->layout = 'default';
will refer to your View\Themed\MyTheme\Layouts\default.ctp.
If cake can't find the requested view file in MyTheme, it will fallback to app/View to find it.
In this way you can override views in your theme as needed.
So if you place your menu in View/Elements/menu.ctp, all of your themes will be able to access it. if you want to overwrite it for MyTheme, simply create an Elements/menu.ctp within MyTheme.
The process is slightly different with previous versions of cake if I recall.
Just place it under /App/Views/Layouts. If you want to use it everywhere, call it default.ctp, it will automatically be used. Otherwise, give it a different name, and then in the controller do:
public function some_action() {
$this->layout = 'mylayout';
}
This will display some_action using your layout instead of the default.

Categories