簡體   English   中英

根據類別將自定義字段添加到joomla前端edit.php

[英]Add custom fields to joomla frontend edit.php based on category

我在joomla com_content文章中添加了一些帶有插件的自定義字段。 我需要在前端編輯器中編輯這些字段,但是這些字段應僅基於類別出現。 萬一我在前端編輯器中選擇類別43時該字段應該出現。

實際上,這些字段出現在articletext字段上方的所有類別上。

edit.php:

<div class="tab-pane active" id="editor">
    <?php echo $this->form->renderField('title'); ?>

    <?php if (is_null($this->item->id)) : ?>
        <?php echo $this->form->renderField('alias'); ?>
    <?php endif; ?>

    <!-- custom fields -->
    <?php echo $this->form->renderField('typ', 'attribs'); ?>
    <?php echo $this->form->renderField('notizen', 'attribs'); ?>
    <!-- end custom fields -->

    <?php echo $this->form->getInput('articletext'); ?>
</div>

我是否可以使用其他基於edit.php中類別ID的方法,還是有其他解決方案?

我很確定您將可以訪問表單對象中的類別。 嘗試類似

$category = $this->form->getValue('catid');
$only_on_these = array(10, 20, 30); // special categories
if (in_array($category, $only_in_these)) {
  // render your custom fields
  echo $this->form->renderField('typ', 'attribs');
  echo $this->form->renderField('notizen', 'attribs');
}
...

這適用於編輯現有內容,但是您需要對新文章進行一些特殊處理,根據您的工作方式,將它們強制初始化為某些類別。

暫無
暫無

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

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