0

I am all new to Typo3. I created an extension called myExtension in /typo3conf/ext/myExtension

The folder structure is as follows

-Classes
 --ViewHelpers
   --myExtensionViewHelper.php
-Resources
 --Resources
  --Private
   --Templates
    --myExtension
     --index.html

myExtensionViewHelper.php has the following code

<?php

/**
 * This class is a demo view helper for the Fluid templating engine.
 *
 * @package TYPO3
 * @subpackage Fluid
 * @version
 */
class Tx_myExtension_ViewHelpers_myExtensionViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {

    /**
     * Renders some classic dummy content: Lorem Ipsum...
     *
     * @param int $length The number of characters of the dummy content
     * @validate $length IntegerValidator
     * @return string dummy content, cropped after the given number of characters
     */
    public function render($length) {
        $dummyContent = 'Lorem ipsum dolor sit amet.';
        return substr($dummyContent, 0, $length);
    }
}

?>

the index.html file contains

{namespace myExtension=Tx_myExtension_ViewHelpers} 

<f:layout name="Default" />
<f:section name="content">

<h1>
  <myExtension:myExtension length="5" />
</h1>

</f:section>

In my typo3 backend, I created a page called "Mango" and included this plugin to it.

I have a template, layout and template.html for the webpage "Mango".

Now what should I do to get the output of the file Index.html into this page?

Am I doing this right ? I haven't done anything else other than the stuff mentioned here.

I'm totally new to Typo3 and all this is a little hard to understand. Please do mention even if anything is trivial and obvious.

Thanks :)

yunzen
  • 32,854
  • 11
  • 73
  • 106
dora
  • 1,314
  • 2
  • 22
  • 38

1 Answers1

3

You need a controller which loads the template system and displays the template. The ViewHelper you have defined is not required to get a result, these are just custom template classes you can use in your templates.

Controller Example:

File: Classes/Controller/TestController.php

class Tx_MyExtension_Controller_TestController extends Tx_Extbase_MVC_Controller_ActionController {
    /**
     * action sampleAction
     *
     * @return void
     */
    public function sampleAction() {
        //Add variables to template
        $this->view->assign("sample_var", "sample value");
    }

}

Now you need a template file which is in a directory based on the Controller and Action. So in this sample you need a template file in my_extension/Resources/Private/Templates/Test/ (where "Test" is the Controller name) which is called like the action Sample.html.

To get a wrap around your extension you also need the Layout file my_extension/Resources/Private/Layouts/Default.html with the content

<div class="tx-my-extension">
    <f:render section="main" />
</div>

This file is called with <f:layout name="Default" /> in your template and <f:render section="main" /> is the place the content will be displayed.

Next step is to allow the action in the extension. Go to your ext_localconf.php in the root directory and add

Tx_Extbase_Utility_Extension::configurePlugin(
    $_EXTKEY,
    'Myextension',
    array(
        'Test' => 'sample', // 'ControllerName' => 'ActionName, OtherAction'
    ),
    // non-cacheable actions
    array(
        'Test' => 'sample', // 'ControllerName' => 'ActionName, OtherAction'
    )
);

Last step is to create the template file my_extension/Resources/Private/Templates/Test/Sample.html with the content

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<f:layout name="Default" />

<f:section name="main">
    Your sample var: {sample_var}
</f:section>

Now you should see the result after adding the Plugin to a page.

Merec
  • 2,751
  • 1
  • 14
  • 21
  • I did that. I created a new Page and in the content part I added the plugin. Page > Edit > Plugin and selected the Plugin. Do I need to also create a template and mention it there as well? – dora May 07 '13 at 06:27
  • Maybe its better when you create an extensnsion using the "extension builder". Create a model there, save and watch the magic. – Merec May 07 '13 at 07:09
  • Most likely this will get you started faster ;) – pgampe May 07 '13 at 15:35