(已退役)使用自定义用户字段中的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?

This is very nice, i forked it and tried to make it a bit more general as a theme component without the Namati specific stuff. Hope you don’t mind!

Added a separate post as well to make it easier to find for others:

2 个赞

Hi all, just wanted to share that I made a very basic plugin version of this. It just lets you specify which user field to make into a link, and—optionally—a prefix (e.g. https://mysite.com/users/). Just thought I’d share in case anyone would rather install a theme component instead of modify code. It’s based on the code in the original post in this thread.

On a side note, for my particular use case, I don’t want any user to be able to edit it; rather, I plan to update it via the discourse API. In that case, would a “custom field” be better than a “user field”? I see both in the API, but custom_fields are blank.

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 的此功能现在可以在新的迷你组件中找到: