johndoe555
johndoe555

Reputation: 101

TYPO3 - Display system categories and sub categories

I am a new typo3 user and actually I'm creating an extension that will allow me to display a list of categories created with the categories of the system, which will contain subcategories (categories and subcategories can have several subcategories), and finally a pdf file

I'm having a little trouble visualizing how to create this extension

Currently, I manage to retrieve and display the parent categories, but I have no idea how to display the different subcategories after clicking on a parent category

Does anyone have an idea how I could display my different subcategories?

there is some code :

Controller : 

    public function listAction()
    {
        $categories = $this->categorieRepository->findByPid(177);
        $this->view->assign(
            'categories' => $categories
        );
    }

List.html

          <div>
            <f:for each="{categories}" as="categorie">
                <f:if condition="{categorie.parent} ">
                    <f:then>
                    </f:then>
                    <f:else>
                        <f:link.action action="list">
                        {categorie.title}
                        </f:link.action>
                    </f:else>
                </f:if>
            </f:for>
        </div>

thanks In advance for your advice

Upvotes: 1

Views: 343

Answers (1)

David
David

Reputation: 6084

Usually the listAction never get's any parameters and the pid is assigned by the storagePid that is automatically fetched by the repository. The repository also can have the setting to ignore the pid. You never mentioned it but as I see the pid in your code you could also include the option to transfer the pid by the URL as parameter.

Additionally, and that's the answer to your question, you can transfer the parent category, so the listAction would have one or two optional parameters. They have to be optional to display also something if no parameters are given:

    public function listAction($parentCategeoryId = null, $pageId = null)
    {
        // HERE SOME LOGIC
        // YOU HAD TO TRANSFER ALSO THE $pageId TO THE REPOSITORY IF USED
        $categories = ...
        $this->view->assign(
            'categories' => $categories
        );
    }

The viewHelper can transfer the parameters if you add them there:

<f:link.action action="list" arguments="{parentCategeoryId: category.uid, pageId: categorie.pid}" >
    {categorie.title}
</f:link.action>

This is no copy-paste answer, so you have still some work, but that's the general approach I'd follow.

Upvotes: 1

Related Questions