ExpressionEngine:有条件地在通道条目表单中显示自定义字段

时间:2011-12-01 16:51:55

标签: content-management-system blogs categories expressionengine

我正在ExpressionEngine中构建一个博客站点。我有两种类型的条目,我想保留在同一个频道中。当选择某个类别时,我想显示其他字段。

**EXAMPLE
Channel > Article
    Fields:
       - Title
       - Post Body
       - Image
       - Tags

    Additional Fields for a category:
       - Price
       - Product Bio

这可能吗?

3 个答案:

答案 0 :(得分:3)

您对JavaScript的了解程度如何?您可以使用Brandon Kelly's CP CSS & JS扩展名。然后使用一点自定义javascript来构建该功能。不完美,但可能比编写自定义扩展更快。粗略地说,你会这样做:

  1. 创建频道字段组和所有频道,并将该组指定给您的频道
  2. 为了使其更有用,您需要类别选择器与字段位于同一个“发布”选项卡上:为该类别创建自定义发布布局,将“类别”字段从“类别”选项卡移动到“发布”选项卡
  3. 找到要隐藏的频道字段的ID号,因为那些将是“发布”页面中的HTML ID,看起来像“hold_field_ID#”
  4. 找出要点击以显示其他字段的类别的类别ID。在“发布”页面中,该类别将显示在“类别”字段中,并带有“value = ID”属性。
  5. 剧本时间!前往附加组件>扩展程序> CP CSS& JS设置并在Custom Javascript字段中添加一些JS。
  6. 这样的事情:

    $(document).ready(function() { 
    
       // Cache the divs with your channel fields  
       var $theSecretFields = $('#hold_field_5, #hold_field_6');
    
       // Hide them
       $theSecretFields.each(function() {
           // But only if they're empty (no previous saved data)
           // If you're using a textarea or something else, change the .find selector
           if ( $(this).find('input').val() === ''  ) { $(this).hide() };
       });
    
       // When you click the category ID (the input[value="id"] selector)...  
       $('#hold_field_category').find('input[value="12"]').click(function() {  
          // Toggle the visibility of the channel fields
          // Again, only show/hide them if they're empty
          $theSecretFields.each( function() {
             // Again, change the .find selector for your field type if necessary
             if ( $(this).find('input').val() === ''  ) { $(this).toggle() };
          });
       });  
    };
    

    您可能必须在点击处理程序中构建更多逻辑,以确保仅在选中复选框时显示字段(以及其他内容),但这是基本想法。

答案 1 :(得分:0)

您想在控制面板或网站的前端进行此操作吗?

答案 2 :(得分:0)

要以类别作为触发器执行此操作,您需要编写一个自定义扩展程序,添加javascript以进行显示和隐藏。

您可能需要查看Entry Type插件,它允许您使用下拉菜单更改显示的字段。