6

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>

6 Answers 6

14

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.

1
  • 1
    It's FLUIDTEMPLATE without an underscore.
    – Daniel
    Oct 17, 2016 at 15:30
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>
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...

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.