英文:
TYPO3 RTE convert <img> to <amp-img>
问题
我有一个TYPO3版本为6.2的网站,正在制作AMP版本。
我在URL中使用条件来加载同一TYPO3页面的不同版本,具体取决于页面版本请求是否为AMP。
页面的常规版本:
页面的AMP版本:
除非我的页面包含在RTE中插入的图像,否则一切正常运作。
在这种情况下,当请求的版本是AMP时,我需要将<img>
转换为<amp-img>
,用于在RTE中插入的图像。
我已经有一个全局变量条件,用于在调用AMP版本时加载自定义TS。
但是不知道如何将<img>
转换为<amp-img>
,你有任何实现这一目标的想法吗?
英文:
I have a TYPO3 version 6.2 website and I am working on a AMP version.
I use a condition in URL to load different versions of the same TYPO3 page depending if the page version request is AMP or not.
Regular version of the page :
AMP version of the page
Everything works fine except if my page contains image inserted in the RTE
In this case I would need to convert <img>
to <amp-img>
for images inserted in the RTE when the version asked is AMP.
I already have a global var condition to load custom TS when AMP version is called.
But no idea how to convert <img>
to <amp-img>
Any idea on how to achieve that?
答案1
得分: 2
if it is only a replacement of the tag name you could try to use a (conditioned) string replacement on one of these levels:
-
the whole page.
you could do astdWrap.replacement
, but that might not work on cached content -
the page content in fluid.
just use a viewhelper to replace text of rendered content. that even could be a typoscript VH:
(<f:cObject typoscriptObjectPath="lib.img2ampimg">{content}</f:cObject>
) -
the page content in typoscript.
depending on whether you render your content with TS you might addstdWrap.replacement
there:
.
page {
10 = FLUIDTEMPLATE
10 {
:
variables {
content < styles.content.get
:
}
}
}
[--your amp condition--]
page.10.variables.content.stdWrap.replacement {
1.search = <img
2.replace = <amp-img
}
[global]
英文:
if it is only a replacement of the tag name you could try to use a (conditioned) string replacement on one of these levels:
-
the whole page.
you could do astdWrap.replacement
, but that might not work on cached content -
the page content in fluid.
just use a viewhelper to replace text of rendered content. that even could be a typoscript VH:
(<f:cObject typoscriptObjectPath="lib.img2ampimg">{content}</f:cObject>
) -
the page content in typoscript.
depending wether you render your content with TS you might addstdWrap.replacement
there:
.
page {
10 = FLUIDTEMPLATE
10 {
:
variables {
content < styles.content.get
:
}
}
}
[--your amp condition--]
page.10.variables.content.stdWrap.replacement {
1.search = <img
2.replace = <amp-img
}
[global]
答案2
得分: 0
也许可以通过扩展程序"Content Replacer"来实现,https://extensions.typo3.org/extension/replacer
英文:
Maybe this could be achieved with the extension "Content Replacer", https://extensions.typo3.org/extension/replacer
答案3
得分: 0
I've solved it as Bernd Wilke suggested, but directly in my fluid template:
<f:if condition="{f:cObject(typoscriptObjectPath:'lib.conditionamp') == 1}">
<f:then>
<v:format.replace substring="<img " replacement="<amp-img layout='responsive'">
<f:format.html>{article.corpsDeTexte}</f:format.html>
</v:format.replace>
</f:then>
<f:else>
<f:format.html>{article.corpsDeTexte}</f:format.html>
</f:else>
</f:if>
Thanks again for your help :)
英文:
I've solved it as Bernd Wilke suggested , but directly in my fluid template :
<f:if condition="{f:cObject(typoscriptObjectPath:'lib.conditionamp')} == 1">
<f:then>
<v:format.replace substring="<img " replacement="<amp-img layout=\"responsive\"">
<f:format.html>{article.corpsDeTexte}</f:format.html>
</v:format.replace>
</f:then>
<f:else>
<f:format.html>{article.corpsDeTexte}</f:format.html>
</f:else>
</f:if>
Thanks again for your help
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论