7

In the Fluid template of plugin I am working on, some things are hardcoded. For instance:

<f:else>
                <li>
                    <v:page.link pageUid="114" />
                </li>
            </f:else>

Since pageUid values are not same on test and production server I would like to make this more dynamic.

I would like to store this somehow in variable and then use the variable in the fluid template.

I just dont know hot to make this and where in TYPO3.

Thanks in advance!

Daniel
  • 6,916
  • 2
  • 36
  • 47
Denis Milosavljevic
  • 365
  • 4
  • 8
  • 17

4 Answers4

10

Because it is an setting do it like this:

Constants:

plugin.myext.settings.detailPid = 123

Setup:

plugin.myext.settings.detailPid = {$plugin.myext.settings.detailPid}

Variables are for variable content. If you have the same PID using variables with TEXT or similiar is overdressed and settings are the correct way.

Also variables are only accessable for FLUIDTEMPLATE content element, not for plugins!

Also in your extbase controller you can access these settings by simple access $this->settings['detailPid']without to render the cObjects first.

In your fluid you can access settings by {settings.detailPid}.

René Pflamm
  • 3,273
  • 17
  • 29
  • 1
    Should that be FLUIDTEMPLATE instead of FLUID_TEMPLATE? – Sybille Peters Jun 02 '23 at 11:11
  • I don't understand this sentence "If you have the same PID using variables with TEXT or similiar is overdressed and settings are the correct way." – Sybille Peters Jun 02 '23 at 11:12
  • @SybillePeters this sentence was related to another answer which used variables and `pageUid = TEXT`. – René Pflamm Jun 05 '23 at 06:46
  • I find this answer a bit difficult to understand. You use the term "Variables". Do you mean variables in FLUIDTEMPLATE? Perhaps it might be helpful to update the answer so it can be clearer. I think it's just those 2 sentences, the rest ist clear. – Sybille Peters Jun 16 '23 at 18:17
5

In typoscript template for your content object FLUIDTEMPLATE:

Typoscript setup/configuration:

10 = FLUIDTEMPLATE
10 {
    variables {
        pageUid = TEXT
        pageUid.value = 114
    }
}

or using constants

Typoscript constants:

pageUid = 114

Typoscript setup/configuration:

10 = FLUIDTEMPLATE
10 {
    variables {
        pageUid = TEXT
        pageUid.value = {$pageUid}
    }
}

Then you can fetch pageUid in your Fluid HTML

<f:else>
    <li>
        <v:page.link pageUid="{pageUid}" />
    </li>
</f:else>

To use variables in a Fluid partial, make sure to pass these along, e.g. by providing _all:

<f:render partial="fluid_part_header" arguments="{_all}" />
Abdull
  • 26,371
  • 26
  • 130
  • 172
jokumer
  • 2,249
  • 11
  • 22
0

If you use EXT:vhs anyways, you can do the following to:

TS-Constants:

pageUid=114

TS-Setup:

settings.pageUid = {$pageUid}

Template (Fluid)

<f:else>
    <li>
        <v:page.link pageUid="{v:variable.typoscript(path: 'settings.pageUid')}" />
    </li>
</f:else>

This will make it available for all FLUID Templates.

randomresult
  • 573
  • 6
  • 14
  • 5
    You don't need vhs to access Typoscript. {f:cObject(typoscriptObjectPath: 'settings.pageUid')}} should do the job, too. can also be replaced by – Paul Beck Jan 31 '17 at 12:42
0

Please consider using jokumer's solution. randomresult's solution would work, but I wouldn't suggest it. You don't need vhs to pass variables. Not talking about Paul Beck`s solution, because it wouldn't work at all. Not anymore at least. (See TYPO3\CMS\Fluid\ViewHelpers\CObjectViewHelper, https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/CObject.html). It accepts only content objects.

Set your Pid in constants like PID_SOME_PAGE = 123 and set a variable in your plugins settings. Like this:

plugin.tx_yourplugin {
  ...
  settings{
    somePage = {$PID_SOME_PAGE}
  }
  ...
}

You can bypass that constants version if you want and set your page id in settings directly. It's just a cleaner way in my opinion, especially for larger websites. Then you can use that variable in your template, like this <f:link.page pageUid="{settings.somePage}">Go to Page</f:link.page>. More options for f:link.page here: https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Link/Page.html

Deividas Šimas
  • 184
  • 1
  • 8