1

I try to show my category uid or name as a class="category.uid" at my FLUID template.

If I try <f:debug>{data}</f:debug> I'll see there are an output like: categories => '1' (1 chars)

But how can I write the category-uid or -name into my FLUID/HTML, similar like this:

<div id="container" class="{data.nav_title}">
<!-- I need the categories --> 
<div id="container" class="{categories.uid}">

THanks for your help.

EDIT: some screenshots The info is in table sys_categorytitle, uid, pid ..

sys_category TYPO3


example some categories overall TYPO3

  • `{data} {data}
user2310852
  • 1,654
  • 1
  • 25
  • 52
  • What is {categories}? Is it array or ObjectStorage? Is it properly mapped in your Domain Model? Please, provide more info. – Viktor Livakivskyi Aug 12 '15 at 08:19
  • TYPO3 Overall Categories (== System records in table sys_category), see my `edit` ..screenshot – user2310852 Aug 12 '15 at 08:56
  • I see now. I didn't work with system categories yet, but most probably you should iterate through them via `f:for` ViewHelper, and then you can fetch an _id_ – Viktor Livakivskyi Aug 12 '15 at 10:21
  • Ok, thanks. I see, that `data`only get an bool variable (1 or 0). With the `f:for`ViewHelper, I only get the uid, not the title. So that's not enough. I will find another way to get my class into the template. thanks – user2310852 Aug 12 '15 at 10:35
  • I've created a feature request for fluid: https://forge.typo3.org/issues/82010 – cweiske Jul 31 '17 at 11:32

3 Answers3

1

The same problem is discussed here (see 11:30 - 12:31).

So there is no viewhelper for this. You have to register a ContentController with Flux.

Ronny Sternecker
  • 237
  • 1
  • 11
  • Writing a custom ViewHelper is a better solution for that task, I thing. See https://stackoverflow.com/a/39224703/2564552 – spackmat Nov 16 '17 at 15:03
1

I have used a variant of the solution here: How can I get the category object in Fluid of Typo3 Content Element Pictures?

TypoScript

lib.categories = CONTENT
lib.categories {
    table = sys_category
    select {
        pidInList = root
        selectFields = sys_category.uid
        join = sys_category_record_mm on sys_category_record_mm.uid_local = sys_category.uid
        where.field = recordUid
        where.wrap = sys_category_record_mm.uid_foreign=|
    }
    renderObj = COA
    renderObj {
        1 = TEXT
        1 {
            field = uid
            stdWrap.noTrimWrap = | cat-||
        }
    }
}

Fluid Template

<f:cObject typoscriptObjectPath="lib.categories" data="{recordUid: data.uid}" />
Community
  • 1
  • 1
maechler
  • 1,257
  • 13
  • 18
  • 1
    This works, but the returned categories are a string and thus must be rendered in TypoScript, not in a for tag within fluid. And also beware that the category entries must on the root element and not a page. And a hint to save time: the resulting SQL query is not shown, when `[SYS][sqlDebug]` is set to 2. – spackmat Nov 16 '17 at 10:04
0

Sorry for the answer - i do not have enough reputation to comment.

What is {data}?

Is it something you get from your controller like?

$data = $this->configurationManager->getContentObject()->data;
$this->view->assign('data', $data);

If so, then you will need to do some extra processing in your controller since $data is an associated array and not an object / model with injection of relations.

Lasse
  • 575
  • 3
  • 14
  • template: I'll get from `{data}`see screenshot above. – user2310852 Aug 12 '15 at 11:14
  • Ok, I see. It´s looks like a page record from the table `pages`. Where do you assign the variable `{data}` to your fluid template? You have properly done something like this in your template controller `$this->view->assign('data' ,$GLOBALS['TSFE']->page);` The `categories => '1'` is not a uid of the category but a count of references used internally by TYPO3 CMS. If you try to add another category then you will see this variable changed to `categories => '2'` – Lasse Aug 12 '15 at 16:26