[英]How to use a typo3 constant in an href?
To make things easier, I can define the main url of my page as a constant in a template: tx_dti.settings.url = https:/someserver/
为了tx_dti.settings.url = https:/someserver/
,我可以在模板tx_dti.settings.url = https:/someserver/
页面的主URL定义为常量: tx_dti.settings.url = https:/someserver/
Now I like to use this constant in my text element to link an internal page eg: 现在,我想在文本元素中使用此常量来链接内部页面,例如:
<a href="{tx_dti.settings.url}?id=13" class="internal-link">Contact Form</a>
Unfortunately my above mentioned approach does not work. 不幸的是,我上面提到的方法不起作用。
What is the correct syntax to replace the server with a constant? 用常量替换服务器的正确语法是什么?
The goal is that I only want to change the constant when I move from a dev to a productive server. 目的是当我从开发人员转移到生产服务器时,我只想更改常量。
in general: 一般来说:
You can not use typoscript constants outside typoscript templates (constants and setup). 您不能在拼写模板(常量和设置)之外使用拼写常量。 If you want to use the value of a typoscript constant in other context you need to transfer the value. 如果要在其他情况下使用印刷文字常量的值,则需要传输该值。
If you want to use the constant in fluid you need to transfer the value to a fluid variable. 如果要在流体中使用常数,则需要将值转换为流体变量。
temp.content = FLUIDTEMPLATE
temp.content {
template = ...
variables {
domain = TEXT
domain.value = {$myTSconstant}
:
}
}
or 要么
settings {
domain = TEXT
domain.value = {$myTSconstant}
:
}
If you want to use the constant in a data field of a content element you might use a marker and replace the marker with typoscript as last step of rendering. 如果要在内容元素的数据字段中使用常量,则可以使用标记并将标记替换为活字,作为呈现的最后一步。
"<p>This is my text and here I use a marker: __MYMARKER__</p>"
the corresponding typoscript: 相应的打字稿:
page {
:
stdWrap.replacement {
1.search = __MYMARKER__
1.replace = {$myTSconstant}
}
}
Note: 注意:
always use TS constants with a $
before the name inside the curly braces. 总是在花括号内的名称前使用带$
TS常量。
Don't confuse it with variable usage in fluid (without $
). 不要将其与流体中的可变用法(没有$
)混淆。
regarding your problem: 关于您的问题:
as Riccardo mentioned: don't use constants for your links, even: don't build your links by hand . 正如Riccardo提到的那样:甚至不要对链接使用常量,甚至: 不要手动建立链接 。 If you really need your domain in urls, automate it with a setting of config.absRefPrefix
(preferrable to config.baseURL
) 如果您确实需要URL中的域,请使用config.absRefPrefix
设置(最好是config.baseURL
)将其自动化。
I guess that you could use config.absRefPrefix
or config.baseURL
(see https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/ ) 我猜您可以使用config.absRefPrefix
或config.baseURL
(请参阅https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/ )
you can set in TypoScript constants: 您可以在TypoScript常量中进行设置:
tx_dti.settings.url = http://myserver
then in TypoScript Setup: 然后在TypoScript安装程序中:
config.baseURL = {$tx_dti.settings.url}
or 要么
config.absRefPrefix = {$tx_dti.settings.url}
Is this sufficient or am I misunderstanding your request? 这足够了还是我误解了您的要求?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.