0

I have a working Extbase extension, that displays a form to the frontend, depending on what options are chosen in the backend whilst putting it on a page.

I use a Flexform for these options (mainly the form action, but also some fields).

Everything works fine, except for the constants. Because this form template might be changed for different websites it is used on, i want to be able to change the template rootpath, so I can define custom templates.

I have a constants.txt and a setup.txt in form_plugin/Configuration/TypoScript

The constants look like this:

plugin.tx_nlmymail_newsletter {
    view {
        # cat=plugin.tx_nlmymail_newsletter/file; type=string; label=Path to template root (FE)
        templateRootPath = EXT:nl_mymail/Resources/Private/Templates/
        # cat=plugin.tx_nlmymail_newsletter/file; type=string; label=Path to template partials (FE)
        partialRootPath = EXT:nl_mymail/Resources/Private/Partials/
        # cat=plugin.tx_nlmymail_newsletter/file; type=string; label=Path to template layouts (FE)
        layoutRootPath = EXT:nl_mymail/Resources/Private/Layouts/
    }
    persistence {
        # cat=plugin.tx_nlmymail_newsletter//a; type=string; label=Default storage PID
        storagePid =
    }
}

My setup.txt looks like this:

plugin.tx_nlmymail_newsletter {
    view {
        templateRootPaths.0 = {$plugin.tx_nlmymail_newsletter.view.templateRootPath}
        partialRootPaths.0 = {$plugin.tx_nlmymail_newsletter.view.partialRootPath}
        layoutRootPaths.0 = {$plugin.tx_nlmymail_newsletter.view.layoutRootPath}
    }
    persistence {
        storagePid = {$plugin.tx_nlmymail_newsletter.persistence.storagePid}
    }
}

So according to this, this should be sufficient. Maybe I'm missing a piece here.

In my ext_tables.php i use

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'mail connection');

To include the Typoscript.

Do I need to make a custom category for my constants?

I compared with the bootstrap_package Plugin, but I can't seem to find the crucial difference.

If someone could point me in the right direction, maybe a part of the documentation I'm missing, I'd be very grateful.

6
  • 1
    Did you include your static file by the template? If yes, then one interesting thing that I see: why do you have once this in your example: form_plugin/Configuration/TypoScript and once plugin.tx_nlmymail_newsletter ? Are they the same? The code self looks fine. Commented Jun 9, 2016 at 15:24
  • Yea, that was a copy mistake. What exactly do you mean with "include your static file by the template"? Commented Jun 9, 2016 at 22:39
  • He means you should add static template from your root template screencast.com/t/kBRp8Y5G1 also you can set "settings" variable so you can get it from your controller like $this->settings Commented Jun 10, 2016 at 5:47
  • @GhanshyamGohel Thanks, it works like that. But shouldnt this be automatic? Is there a possibility to make this happen on its own? Commented Jun 10, 2016 at 8:13
  • @Eupides: No, it should not work automatically - some configurations are optional, and sometimes you just don't want to include an extensions configuration. You can however include it automatically, but no idea how to do that (extbase does it, so maybe look into extbases code?). Commented Jun 10, 2016 at 12:41

1 Answer 1

4

Copied from the comments:

The problem was that the static template was not included in the Template.

Here is a screenshot:

enter image description here

Is it pissible to do so automatically?

Yes, it is but only with string based functions and not as a file.

You have to use the following commands in your ext_localconf.php:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript

or

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptConstants
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptSetup

Example from the felogin system extension:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript('TYPO3.CMS.Felogin', 'constants', '
styles.content.loginform {
    # cat=content/cLogin; type=int+; label= PID of user archive: Enter the page-uid number (PID) of the folder where you keep your fe_users that are supposed to login on this site. This setting is necessary, if login is going to work!
  pid =
    # cat=content/cLogin; type=; label= Login template: Enter the path for the HTML template to be used
  templateFile = EXT:felogin/Resources/Private/Templates/FrontendLogin.html
}
', 'defaultContentRendering');

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript('TYPO3.CMS.Felogin', 'setup', '
# Setting "felogin" plugin TypoScript
tt_content.login = COA
tt_content.login {
    10 =< lib.stdheader
    20 >
    20 =< plugin.tx_felogin_pi1
}
', 'defaultContentRendering');

Finally:

It is recommended to work with the static templates as you may have different trees and settings. Most of the TER extensions are using this approach as well.

Sign up to request clarification or add additional context in comments.

1 Comment

If you're wanting to add your typoscript files directly you can add \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript('<INCLUDE_TYPOSCRIPT: source="FILE:typo3conf/ext/myextension/Configuration/TypoScript/setup.typoscript">'); to the file typo3conf/ext/myextension/ext_localconf.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.