TYPO3 RTE将<img>转换为<amp-img>。

huangapple go评论58阅读模式
英文:

TYPO3 RTE convert <img> to <amp-img>

问题

我有一个TYPO3版本为6.2的网站,正在制作AMP版本。

我在URL中使用条件来加载同一TYPO3页面的不同版本,具体取决于页面版本请求是否为AMP。

页面的常规版本:

https://www.novethic.fr/actualite/environnement/climat/isr-rse/rencontre-avec-danone-un-des-rares-francais-a-aligner-sa-strategie-sur-l-objectif-2-c-145150.html

页面的AMP版本:

https://www.novethic.fr/amp/actualite/environnement/climat/isr-rse/rencontre-avec-danone-un-des-rares-francais-a-aligner-sa-strategie-sur-l-objectif-2-c-145150.html

除非我的页面包含在RTE中插入的图像,否则一切正常运作。

在这种情况下,当请求的版本是AMP时,我需要将&lt;img&gt;转换为&lt;amp-img&gt;,用于在RTE中插入的图像。

我已经有一个全局变量条件,用于在调用AMP版本时加载自定义TS。

但是不知道如何将&lt;img&gt;转换为&lt;amp-img&gt;,你有任何实现这一目标的想法吗?

英文:

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 :

https://www.novethic.fr/actualite/environnement/climat/isr-rse/rencontre-avec-danone-un-des-rares-francais-a-aligner-sa-strategie-sur-l-objectif-2-c-145150.html

AMP version of the page

https://www.novethic.fr/amp/actualite/environnement/climat/isr-rse/rencontre-avec-danone-un-des-rares-francais-a-aligner-sa-strategie-sur-l-objectif-2-c-145150.html

Everything works fine except if my page contains image inserted in the RTE

In this case I would need to convert &lt;img&gt; to &lt;amp-img&gt;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 &lt;img&gt; to &lt;amp-img&gt;
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 a stdWrap.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:
    (&lt;f:cObject typoscriptObjectPath=&quot;lib.img2ampimg&quot;&gt;{content}&lt;/f:cObject&gt;)

  • the page content in typoscript.
    depending on whether you render your content with TS you might add stdWrap.replacement there:

.

page { 
    10 = FLUIDTEMPLATE
    10 {
        :
        variables {
            content &lt; styles.content.get
            :
        }
    }
}

[--your amp condition--]
    page.10.variables.content.stdWrap.replacement {
        1.search = &lt;img
        2.replace = &lt;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 a stdWrap.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:
    (&lt;f:cObject typoscriptObjectPath=&quot;lib.img2ampimg&quot;&gt;{content}&lt;/f:cObject&gt;)

  • the page content in typoscript.
    depending wether you render your content with TS you might add stdWrap.replacement there:

.

page { 
    10 = FLUIDTEMPLATE
    10 {
        :
        variables {
            content &lt; styles.content.get
            :
        }
    }
}

[--your amp condition--]
    page.10.variables.content.stdWrap.replacement {
        1.search = &lt;img
        2.replace = &lt;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 :

&lt;f:if condition=&quot;{f:cObject(typoscriptObjectPath:&#39;lib.conditionamp&#39;)} == 1&quot;&gt;
 &lt;f:then&gt;
    &lt;v:format.replace substring=&quot;&lt;img &quot; replacement=&quot;&lt;amp-img layout=\&quot;responsive\&quot;&quot;&gt;
        &lt;f:format.html&gt;{article.corpsDeTexte}&lt;/f:format.html&gt;
    &lt;/v:format.replace&gt;
 &lt;/f:then&gt;
 &lt;f:else&gt;
    &lt;f:format.html&gt;{article.corpsDeTexte}&lt;/f:format.html&gt;
 &lt;/f:else&gt;
&lt;/f:if&gt;

Thanks again for your help
TYPO3 RTE将<img>转换为<amp-img>。

huangapple
  • 本文由 发表于 2020年1月3日 22:02:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579898.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定