XF 2.0 Code embed not working like it did in 1.x

Foxum

Member
I have updated my forum to 2.0.4 and this code works but the custom field does not output the right thing it seems. You can see below when supplied a specific youtube channel it works, but when it relies on a custom field it does not work as shown in the red high lighted code.

Intended use: User adds their custom channel ID inside of their forum profile and subscribe button shows their personal channel.

Current problem: The custom field I specify gives no value and returns with an error.

Below is the code, as you can see I underlined the problem in red and not sure where to go to fix this issue.

dhEoyz8.png


Below image is what it looks like currently, as you can see it does work with GoogleDevs but not with custom field supplied in forum profile of users.

xQ91Od8.png


Below this is the custom field entry found on the user profile

JYLNU7M.png


I covered it pretty well and it for sure seems to be some kind of style issue but this is how the embed works https://developers.google.com/youtube/youtube_subscribe_button

ps. Manually adding my channel ID as shown above does work, I have narrowed it down to being something with custom field or style code. I am quite stuck.

The custom field is just standard and is called "youtube" nothing special.

Code:
<script src="https://apis.google.com/js/platform.js"></script>
<div class="g-ytsubscribe" data-channel="GoogleDevelopers" data-layout="full" data-count="default"></div>

    <xen:if is="{$message.customFields.youtube}">
<div class="g-ytsubscribe" data-channel="{$message.customFields.youtube}" data-layout="full" data-count="default"></div>
        </xen:if>
 
Last edited:
First thing I see is <xen:if should be <xf:if
Does not seem to be the problem, I also tried removing the whole "if" thing and the problem still persist. I have modified the code a bit to use channelid which works better. As you can see when I manually type in the channel id data-channelid="UCp-L1xcDs8IVxxNymYxbFPA" it works but when I use data-channelid="{$message.customFields.youtube}" it does not work despite UCp-L1xcDs8IVxxNymYxbFPA being in the custom field. In theory (at least I believe), my profile should put UCp-L1xcDs8IVxxNymYxbFPA in place of {$message.customFields.youtube although that does not seem to be the case.

1524843115474.webp

As you can see it successfully outputs but the customField youtube is having issues.

1524843170766.webp
 
That may not be the correct way of accessing custom fields from a user.

I figured the official documentation by xenforo does not cover custom fields well https://xenforo.com/help/custom-user-fields/. I tried using user.Profile.customFields.youtube and user.customFields.youtube and bunch of others. From what I can gather, I should not need to go too specific and crazy with custom fields because the documentation says "Normally, custom fields value that are shown in the user interface will simply display the value for the field" which exactly what I need, for the plain text profile entry to show up in place of {$message.customFields.youtube) and work with the API. Unless I am not understanding this correctly I feel custom field is incorrect and I do not know how to get the value inside of "youtube" inside of datachanenlid=" "

Below is the custom field I am trying to get the value of

1524846478018.webp
 
I figured it out! :D

<div class="g-ytsubscribe" data-channel="{$message.customFields.youtube}" data-layout="full" data-count="default"></div>
</xen:if>

You forgot to data=channel to be data-channelid=

This is what ended up working for us:

<xf:if is="{$user.Profile.custom_fields.youtube}">
<div class="g-ytsubscribe" data-channelid="{$user.Profile.custom_fields.youtube}" data-layout="full" data-count="default"></div>
</xf:if>
 
Top Bottom