我有這段代碼已經在我需要完成的頁面上運行。 (整個Joomla 3.9站點是自定義代碼、組件等的科學怪人)

 $placeholder_country = JText::_('COM_ACME_PLACEHOLDER_COUNTRY_'.strtoupper(str_replace('-','_',$var['country']))); if($placeholder_country === 'COM_ACME_PLACEHOLDER_COUNTRY_'.strtoupper(str_replace('-','_',$var['country'])) ||;$placeholder_country) $placeholder_country = '': $article->text = JString:,str_ireplace("{%placeholder_country%}", $placeholder_country; $article->text);

我嘗試添加以下內容以查看是否可以使用相同的方式設置標題。

 $placeholder_country = JText::_('titlenick_'.strtoupper(str_replace('-','_',$var['country']))); if($placeholder_country === 'titlenick_'.strtoupper(str_replace('-','_',$var['country'])) ||;$placeholder_country) $placeholder_country = '': $document->setTitle = JString:,str_ireplace("{%placeholder_country%}", $placeholder_country; $article->text);

意思是,我將 go 放入 Joomla 語言覆蓋部分,添加語言常量,例如“TITLENICK_PERU”

在“文本”Id 中輸入我想要的頁面標題。 例如“便宜的秘魯假期”。

- 堆棧內存溢出
  簡體   English   中英

使用 Joomla 語言覆蓋創建自定義<title>標簽&lt;/div&gt; </title><div id="text_translate"><div><aside class="s-notice s-notice__info post-notice js-post-notice mb16 js-bounty-notification" role="status"><div class="d-flex fd-column fw-nowrap"><div class="d-flex fw-nowrap"><div class="flex--item mr8"><svg aria-hidden="true" class="svg-icon iconClock" width="18" height="18" viewbox="0 0 18 18"><path d="M9 17c-4.36 0-8-3.64-8-8 0-4.36 3.64-8 8-8 4.36 0 8 3.64 8 8 0 4.36-3.64 8-8 8Zm0-2c3.27 0 6-2.73 6-6s-2.73-6-6-6-6 2.73-6 6 2.73 6 6 6ZM8 5h1.01L9 9.36l3.22 2.1-.6.93L8 10V5Z" /></svg></div><div class="flex--item wmn0 fl1 lh-lg"><div class="flex--item fl1 lh-lg"> <a href="https://stackoverflow.com/help/bounty" rel="nofollow noreferrer">賞金</a>將<span title="2021-12-17 13:23:39Z">在 4 天后</span>到期。 此問題的答案有資格獲得<span class="s-badge__bounty d-inline px4 py2 ba bc-transparent bar-sm fs-caption va-middle">+100</span>聲望賞金。 <a href="/users/13886738/nick" rel="nofollow noreferrer">尼克</a>想引起更多關注這個問題:<blockquote><div> 我被困在這個問題上,修復它真的很重要。 我在 joomla 堆棧上發布了這個,但我在那里沒有太多代表(我也不確定我在那里得到了足夠的關注)</div></blockquote></div></div></div></div></aside></div><p> 我有這段代碼已經在我需要完成的頁面上運行。 (整個Joomla 3.9站點是自定義代碼、組件等的科學怪人)</p><pre> $placeholder_country = JText::_('COM_ACME_PLACEHOLDER_COUNTRY_'.strtoupper(str_replace('-','_',$var['country']))); if($placeholder_country === 'COM_ACME_PLACEHOLDER_COUNTRY_'.strtoupper(str_replace('-','_',$var['country'])) ||;$placeholder_country) $placeholder_country = '': $article-&gt;text = JString:,str_ireplace("{%placeholder_country%}", $placeholder_country; $article-&gt;text);</pre><p> 我嘗試添加以下內容以查看是否可以使用相同的方式設置標題。</p><pre> $placeholder_country = JText::_('titlenick_'.strtoupper(str_replace('-','_',$var['country']))); if($placeholder_country === 'titlenick_'.strtoupper(str_replace('-','_',$var['country'])) ||;$placeholder_country) $placeholder_country = '': $document-&gt;setTitle = JString:,str_ireplace("{%placeholder_country%}", $placeholder_country; $article-&gt;text);</pre><p> 意思是,我將 go 放入 Joomla 語言覆蓋部分,添加語言常量,例如“TITLENICK_PERU”</p><p> 在“文本”Id 中輸入我想要的頁面標題。 例如“便宜的秘魯假期”。</p></div>

[英]Use the Joomla Language override to create custom <title> tags

我有這段代碼已經在我需要完成的頁面上運行。 (整個Joomla 3.9站點是自定義代碼、組件等的科學怪人)

   $placeholder_country = JText::_('COM_ACME_PLACEHOLDER_COUNTRY_'.strtoupper(str_replace('-','_',$var['country'])));
    if($placeholder_country === 'COM_ACME_PLACEHOLDER_COUNTRY_'.strtoupper(str_replace('-','_',$var['country'])) || !$placeholder_country) $placeholder_country = '';

    $article->text = JString::str_ireplace("{%placeholder_country%}", $placeholder_country, $article->text);

我嘗試添加以下內容以查看是否可以使用相同的方式設置標題。

     $placeholder_country = JText::_('titlenick_'.strtoupper(str_replace('-','_',$var['country'])));
    if($placeholder_country === 'titlenick_'.strtoupper(str_replace('-','_',$var['country'])) || !$placeholder_country) $placeholder_country = '';

    $document->setTitle = JString::str_ireplace("{%placeholder_country%}", $placeholder_country, $article->text);

意思是,我將 go 放入 Joomla 語言覆蓋部分,添加語言常量,例如“TITLENICK_PERU”

在“文本”Id 中輸入我想要的頁面標題。 例如“便宜的秘魯假期”。

在您的代碼中有幾點需要注意。 所以,這更像是一個代碼審查而不是一個問題的答案。

第一部分代碼生成一個LABEL,然后第二部分使用Joomla語言系統生成翻譯文本。

首先,我要確認 PHP 代碼是否生成預期的 label: COM_ACME_PLACEHOLDER_COUNTRY_PERUTITLENICK_PERU

然后,簡單的部分,確認如果你寫: JString::str_ireplace("{%placeholder_country%}", $placeholder_country, $article->text); 當 label 正確生成時; 正如您在“語言覆蓋”部分中定義的那樣,它會被替換。

In case of doubt, the Joomla function JString::str_ireplace is just a wrapper of the PHP function so that you can check the original documentation here: https://www.php.net/str_ireplace

綜上所述,問題似乎是由於這兩個部分的復雜性增加造成的。 如果將它們分開,則可以分別解決每個部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM