(已退役)使用自定义用户字段中的ID链接到用户的外部资料

Also today I realized that the User Profile page actually displays the custom field as it should, although compared to the user card, now the custom field (Website) is displayed last instead of first…

Capture

1 个赞

I feel like I’ve seen a discussion of this, but I can’t find it now.

I’ve got a custom profile field that holds a user’s website implemented using this tutorial, but allowing for any external site to be entered, rather than just linking to Twitter or something. The problem I have is that about 80% of the users don’t bother to put “http(s)://” in front of the URL they enter. They (rightly) expect that “www.example.com” should just work. So how do I make it just work?

Edited to add: Figured it out. Below is the entire if block of javascript I used to determine whether to attempt to show an external link. The inner if is what determines whether the external URL needs to have “http” added to it, and takes care of doing it.

    if (userFields && userFields[churchURLFieldId]) {
      const rawChurchURL = userFields[churchURLFieldId];
      var url = rawChurchURL;
      if (!/^https?:\/\//i.test(rawChurchURL)) {
        url = 'http://' + rawChurchURL;
      }
      const link = "<a href='"+url+"' target='_blank'>"+userFields[churchNameFieldId];+"</a>";
      return Ember.Object.create({ link, name: churchURL.get('name') });
    } else {
      return null;
    }
1 个赞

Is there a way to edit existing user profile fields rather than adding new one? So that the existing twitter field value can be edited to contain anchor tag

the main post that allows us to add new clickable profile fields using connectors/handlebar outlets etc, those get “added” and so I had to hide the existing profile fields
e.g. I could add a clickable twitter field and so have to hide the existing twitter field
Now the newly added twitter field will be in a separate div rather than belonging to that same ember div which was pre-existing, resulting in weird css

Would using /connectors/user-profile-public-fields/Twitter instead of using /connectors/user-profile-primary/ help here?

这非常好,我 fork 了它,并尝试将其作为一个更通用的主题组件,去掉了 Namati 特有的内容。希望您不介意!

我还单独发了一篇帖子,方便其他人查找:

2 个赞

大家好,想分享一下,我制作了一个非常基础的 插件版本。它允许你指定将哪个用户字段转换为链接,并可选择性地添加前缀(例如 https://mysite.com/users/)。之所以分享出来,是考虑到有些人可能更愿意安装主题组件,而不是直接修改代码。该插件基于本线程原始帖子中的代码。

顺便提一下,针对我的具体使用场景,我不希望任何用户能够编辑它;相反,我计划通过 Discourse API 来更新它。在这种情况下,使用“自定义字段”(custom field)是否比“用户字段”(user field)更合适?我在 API 中看到了两者,但 custom_fields 是空的。

7 个赞

@wilson29thid 您是否愿意为该组件设置一个#theme主题?将其作为可安装的主题组件而不是每次都要求人们复制粘贴代码会很棒。

5 个赞

当然——在这里创建一个带有该标签的主题是否可以安装?

1 个赞

它已经可以通过 git URL 安装。创建一个主题将有助于人们更容易地找到它。

1 个赞

有一个稍微不同的问题。我想在注册页面的用户字段描述中添加一个在新窗口中打开的链接。该页面不识别用 [此](格式) 包装的链接。

我希望用户在加入之前同意他们已阅读我们的社区价值观,并且在那里有一个链接可以帮助他们,如果他们错过了。现在我只是告诉他们将完整链接复制/粘贴到他们的浏览器中。

Discourse 3.2 和 Ember 5 的工作方式是怎样的?

我已经更新了版本:\u003cscript type=\"1.13.0\" version=\"1.13.0\"\u003e 并将 api.registerConnectorClass 更改为 api.renderInOutlet,正如此处所建议的那样,但在浏览器控制台中收到:[THEME 27] Error: klass is not an Ember component

我已经将 property 替换为 computed,正如此处所建议的那样,但在浏览器控制台中收到:[THEME 27] ReferenceError: computed is not defined

哦,我忘了导入,所以我将缺失的 import EmberObject, { computed } from '@ember/object'; 添加到脚本标签的开头,但这会导致 SyntaxError:“/discourse/theme-27/discourse/initializers/theme-field-140-common-html-script-3: ‘import’ and ‘export’ may only appear at the top level。”

1 个赞

嗯,是的,OP 中建议的技术已经 pretty outdated(考虑到它写于 2016 年,这 pretty makes sense :sweat_smile:)。

如今,这类东西应该打包到一个 git 仓库中,并发布为一个 Theme component,供人们通过设置进行安装和配置。

2 个赞

不过,我确实重新修改了 @wilson29thid 的 TC 在这里,尽管它仍然有一个弃用警告,我需要找个时间修复它。

1 个赞

OP 的此功能现在可以在新的迷你组件中找到: