为用户建议页面标题

时间:2016-08-17 12:09:28

标签: plone plone-5.x

在新Plone页面的添加页面上,我想通过将其添加到标题表单字段中来建议从文件夹标题派生的用户的标题。 在我的Plone实例中实现该行为的最佳实践是什么?

3 个答案:

答案 0 :(得分:3)

另一种解决方案可以是使用Javascript,分别是jQuery:

(function($) { $(document).ready(function() {

  // A Dexterity-based document is added:
  if( window.location.href.endsWith('/++add++Document') ) {

    // Grab the parent's title of the current title-tag's content:
    var title = $('title')[0].innerHTML.split(' — ')[0]

    // Prefill the new document's title-field with the parent's title:
    $('#form-widgets-IDublinCore-title').val(title)
  }

  // An Archetypes-based document is added:
  if( window.location.href.indexOf('/portal_factory/Document/') > -1 ) {
    var parentUrl= document.referrer
    var parentTitleEleId = 'parent-fieldname-title'

    // Provide ele to load parent's title into:
    var loadEle = document.createElement('span')

    // Load parent's title into ele:
    $(loadEle).load(parentUrl + ' #' + parentTitleEleId, function() {

      // After loading finished, fetch parent-title of ele, remove
      // trailing spaces and set it into the new doc's title-field:
      $('#title').val(loadEle.childNodes[0].innerHTML.trim())

      // Thy had served y'er purpose, vanish:
      loadEle.remove()

    });

  }

});})(jQuery);

答案 1 :(得分:1)

您可以在Docs找到更多关于MonkeyPatching的信息。另一种解决方案是,您可以注册自己的AddForm并设置Textline-Widget的值。要创建自定义AddForm,请查看Docs

答案 2 :(得分:0)

您可以对Basic metadata行为进行monkeypatch或子类化以修改_get_title的行为:https://github.com/plone/plone.app.dexterity/blob/master/plone/app/dexterity/behaviors/metadata.py#L350-L351

相关问题