Fluid Typo3 - How to get variables definded via flux from different page uids

爷,独闯天下 提交于 2021-01-27 13:42:36

问题


I guess my problem is easily solved, but I'm thinking for days about it, googling didn't help me out. Maybe I just don't understand the concept :-).

In my provider extension I define a simple main page with one configuration option. Depending on what "fontawesomeicon" says for a page, its corresponding Fonteawesome-Icon shall be placed before the menu entry text. But when I implement it this way, every page menu entry gets the Icon from the actual page. I don't know how to tell the system, that the corresponding {fontawesomeicon} shall be taken from that page this entry belongs to.

Thanks for any hints to get it working. I'm useing Typo3 7.1

Page config Fullpage.html:

<f:section name="Configuration">
    <flux:form id="fullpage" />
    <flux:grid>
        <flux:grid.row>
            <flux:grid.column colPos="0" name="main" />
        </flux:grid.row>
    </flux:grid>
    <flux:field.input name="fontawesomeicon" />
</f:section>

Partial config Elements.html:

<f:section name="MainMenu">
    <ul class="sf-menu">
        <v:page.menu pageUid="{settings.startpageUid}" entryLevel="2" levels="2" expandAll="TRUE" as="menu">
            <f:for each="{menu}" as="item">
                <li class="{item.class}">
                    <a href="{item.link}"><i class="fa fa-lg {fontawesomeicon}"></i>&nbsp;{item.linktext}</a>
                    <f:if condition="{item.hasSubPages}">
                        <ul>
                            <f:render section="SubMenu" arguments="{_all}" />
                        </ul>
                    </f:if>
                </li>
            </f:for>
        </v:page.menu>
    </ul>
</f:section>

<f:section name="SubMenu">
    <v:page.menu pageUid="{item.uid}" entryLevel="2" levels="1" as="submenu">
        <f:for each="{submenu}" as="subitem">
            <li class="{subitem.class}">
                <a href="{subitem.link}"><i class="fa {fontawesomeicon}"></i>&nbsp;{subitem.linktext}</a>
            </li>
        </f:for>
    </v:page.menu>
</f:section>

Just to complete it... putting it together in the page layout file Page.html:

<f:layout name="Page" />
<f:render section="MainMenu" partial="Elements" arguments="{_all}" />
<f:render section="Main" />

回答1:


Finally got it. It's the old problem... how do you ask the right question if you don't get to the real matter. Another post (about accessing flexform) gave me the final hint. Yay!

<f:section name="MainMenu">
    <ul class="sf-menu">
        <v:page.menu pageUid="{settings.startpageUid}" entryLevel="2" levels="2" expandAll="TRUE" as="menu">
            <f:for each="{menu}" as="item">
                <li class="{item.class}">
 <!--new:-->        <flux:form.data table="pages" field="tx_fed_page_flexform" uid="{item.uid}" as="menuIcon">
                        <a href="{item.link}"><i class="fa fa-lg {menuIcon.fontawesomeicon}"></i>&nbsp;{item.linktext}</a>
 <!--new:-->        </flux:form.data>
                    <f:if condition="{item.hasSubPages}">
                        <ul>
                            <f:render section="SubMenu" arguments="{_all}" />
                        </ul>
                    </f:if>
                </li>
            </f:for>
        </v:page.menu>
    </ul>
</f:section>

<f:section name="SubMenu">
    <v:page.menu pageUid="{item.uid}" entryLevel="2" levels="1" as="submenu">
        <f:for each="{submenu}" as="subitem">
            <li class="{subitem.class}">
 <!--new:-->    <flux:form.data table="pages" field="tx_fed_page_flexform" uid="{subitem.uid}" as="subMenuIcon">
                    <a href="{subitem.link}"><i class="fa {subMenuIcon.fontawesomeicon}"></i>&nbsp;{subitem.linktext}</a>
 <!--new:-->    </flux:form.data>
            </li>
        </f:for>
    </v:page.menu>
</f:section>



回答2:


By using the variable "fontawesomeicon" directly, the value is always the same, as set in the controller that renders the template, you need to specify a new context.

Debug the variables in the foreach-loop with <f:debug>{varname}</f:debug> and check if the field "fontawesomeicon" is present.

<f:section name="SubMenu">
    <v:page.menu pageUid="{item.uid}" entryLevel="2" levels="1" as="submenu">
        <f:for each="{submenu}" as="subitem">
            <li class="{subitem.class}">
                <f:debug>{subitem}</f:debug>
                <a href="{subitem.link}"><i class="fa {fontawesomeicon}"></i>&nbsp;{subitem.linktext}</a>
            </li>
        </f:for>
    </v:page.menu>
</f:section>

I also recommend to use TypoScript (HMENU, TMENU) for menus instead of Fluid-Templates



来源:https://stackoverflow.com/questions/31555978/fluid-typo3-how-to-get-variables-definded-via-flux-from-different-page-uids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!