简体   繁体   English

根据类别将自定义字段添加到joomla前端edit.php

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

I added a few custom fields with a plugin to my joomla com_content articles. 我在joomla com_content文章中添加了一些带有插件的自定义字段。 I need to edit these fields in the frontend editor but the fields should just appear based on the category. 我需要在前端编辑器中编辑这些字段,但是这些字段应仅基于类别出现。 In case the field should just appear when i select category 43 in the frontend editor. 万一我在前端编辑器中选择类别43时该字段应该出现。

Actually the fields appear on all categories in above the articletext field. 实际上,这些字段出现在articletext字段上方的所有类别上。

edit.php: 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>

Can i use if else based on a category id in edit.php or is there another solution? 我是否可以使用其他基于edit.php中类别ID的方法,还是有其他解决方案?

I am pretty sure you will have access to the category in your form object. 我很确定您将可以访问表单对象中的类别。 Try something like 尝试类似

$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');
}
...

This works for editing existing content, but you'll need to do some special handling for new articles, forcing them initialized with some categories, depending on how you want this to work. 这适用于编辑现有内容,但是您需要对新文章进行一些特殊处理,根据您的工作方式,将它们强制初始化为某些类别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM