Check if pid of current page is X
Asked Answered
B

6

7

How can I check if a page has a specific ID, and if true output a text?

I thought about something like this (pseudocode):

<f:if condition="{current.page.uid}=='78'">
    <p>I am Page 78</p>
</f:if>
Baiss answered 17/10, 2016 at 14:12 Comment(0)
M
16

If you want to use this in an FLUIDTEMPLATE (page.10 = FLUIDTEMPLATE as example) you can access the page data with {data.uid}.

<f:if condition="{data.uid} == 78">
  <p>I am Page 78</p>
</f:if>

In an extbase Extension you can make it like @dimitri-l says.

Matsu answered 17/10, 2016 at 15:29 Comment(1)
It's FLUIDTEMPLATE without an underscore.Hiers
P
6

You can fetch current page ID via typoscript object

typoscript:

lib.currentPageId = TEXT
lib.currentPageId.data = TSFE:id

FLUID:

<f:if condition="{f:cObject(typoscriptObjectPath:'lib.currentPageId')}==78">
    <p>I am Page 78</p>
</f:if>
Pacifically answered 17/10, 2016 at 14:41 Comment(0)
B
3

You can make a variable into your "page TS setup" like here :

variables {
    pageUid = TEXT
    pageUid.field = uid
    ...
}

So you can make your fluid condition as here :

<f:if condition="{pageUid}=={settings.homepid}">
    <p>I am Page 78</p>
</f:if>

for exemple...

Bomber answered 7/3, 2017 at 12:49 Comment(0)
W
2

You would need to pass the page id to the fluid template. If you are using an Extbase controller you can pass $GLOBALS['TSFE']->id to your view and then use an if condition as you did.

$this->view->assign('pageId', $GLOBALS['TSFE']->id);

I am not sure if it is already possible to do string comparison in Typo3 6.2, if not, you have to compare it that way:

<f:if condition="{0:pageId} == {0:'78'}>
...
</f:if>

Otherwise this is a clean solution for current versions

<f:if condition="{pageId} == '78'>
...
</f:if>
Wile answered 17/10, 2016 at 14:38 Comment(0)
S
1

With the VHS viewhelper you can do it with fluid only, no need for a Typoscript helper:

{namespace v=FluidTYPO3\Vhs\ViewHelpers}

<f:if condition="{v:page.info(field: 'uid')} == '21'">
    <f:then>
        Shows only if page ID equals 21.
    </f:then>
</f:if>
Swatow answered 21/12, 2017 at 8:41 Comment(0)
D
0

Sometimes you need to give a link a class when the link target is the current page (here: uid=1). The inline version helps:

<f:link.page pageUid="1"
        class="{f:if(condition: '{data.uid} == 1', then: ' current')}">
           Link
</f:link.page>
Drawback answered 4/11, 2022 at 7:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.