Check if pid of current page is X

14,700

Solution 1

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.

Solution 2

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>

Solution 3

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>

Solution 4

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...

Solution 5

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>
Share:
14,700
Black
Author by

Black

Full-Stack Webdeveloper Magento 1, Magento 2 &amp; more.

Updated on July 05, 2022

Comments

  • Black
    Black almost 2 years

    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>
    
  • Daniel
    Daniel over 7 years
    It's FLUIDTEMPLATE without an underscore.