Search code examples
typo3typo3-extensionstypo3-7.6.x

TYPO3 move site from fileadmin into an own extension


I have a TYPO3 version 7.6.2 installation. I have a test.html and a test.css file inside the fileadmin under fileadmin/site/template/test.html and test.css.

Now as a template I have this under the category setup:

page >

page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
file = fileadmin/site/template/test.html
}

config.no_cache = 1
config.contentObjectExceptionHandler = 0

This works all fine as intended.

But I heard that it is possible and desirable to separate your own files from the fileadmin, which is thought for user files. I heard one can factor them out into an own extension. Now my question would be how? I did the basic tutorial on how to build your own first extension, but it is still not clear to me how to re factor the code i have in test.html and test.css into an own extension. Any kind of resource or advice would be useful.


Solution

  • Create a folder in typo3conf/ext with the name your extension should have. Create an ext_emconf.php (copy from another extension and change the values) so that TYPO3 can install it.

    Move your template file from fileadmin to Resources/Private/Templates/Page/Test.html in your extension. This could be any other place in your extension but there are structuring conventions wich I suggest to follow.

    Now change the TypoScript to

    file = EXT:your_extension_name/Resources/Private/Templates/Page/Test.html
    

    Move the CSS and JS files (and everything else wich needs to be publicly available for web requests) to Resources/Public/CSS, resp. Resources/Public/JavaScript in your extension. Include the files with the same syntax (EXT:my_extension_name/Resources/Public/...) in your TypoScript.

    You should also consider to move your TypoScript to Configuration/TypoScript/setup.txt in your extension. And then include it with

    <INCLUDE_TYPOSCRIPT source:'FILE:EXT:my_extension_name/Configuration/TypoScript/setup.txt'>
    

    in the backend.

    Dont forget to install your extension :)

    You can read more about good practices in TYPO3 extensions here.