Forum Discussion

Inactive User's avatar
Inactive User
13 years ago

Editing Blog Component

(Assuming we have already had added to our environment a custom profile field, location)... On a blog post, is there a way to add a profile field's information (such as location) to the line displaying the author username/date authored?

 

I know the line is editable using Toolbelt, but if its possible, would like to know what the syntax would be to add information from the profile there. 

 

Thanks in advance for your help!

  • AdamN's avatar
    AdamN
    13 years ago

    Unfortunately you're not going to be able to accomplish this with a text change alone, since this type of customization requires pulling in dynamic content. You'll need a custom component for retreiving the user's profile location, and then displaying the content. This custom component will replace the "message-header' component on the "Blog Message" page. Because the "message-header" contains a few different elements (such as the author info, date, and subject), you'll need to account for those as well.

     

    This is a very crude example component, but hopefully will get you started in the right direction:

    <#assign userLocation = rest("/users/id/${env.context.message.author.id?c}/profiles/name/userlocation").value />
    
    <@component id="subject" />
    <@component id="author" />
    | ${userLocation} |
    <@component id="post-date" />

     This doesn't have any error handling for the REST API call, so that may be something you'd want to add in. You may also need to use "restadmin" instead of "rest" depending on the permissions of that particular custom profile field. Some text string changes may needed as well get the exact result you're looking for.

     

    I hope this helps!

     

     

     

     

  • Inactive User's avatar
    Inactive User

    I found the text key, profile.userlocation.title... I can get the label to display... but how about the value?

    • Inactive User's avatar
      Inactive User
      I found another post about the use of env.context.message.author... but what would be needed after author to get the information?
      .profile.userlocation and .userlocation don't work.
  • AdamN's avatar
    AdamN
    Khoros Oracle

    Hi jlutterloh,

     

    If I understand correctly what you're trying to accomplish, you'll likely need to add a custom component to the Blog Message page. This custom component would get details of the message author via one of the custom context objects available through FreeMarker, and would use this information to make a REST API call to get the value of the custom profile field. You would then display the resulting value, formatted as desired.

     

    This post has some pretty good details of how to do a customization just like that. I'd suggest checking it out and letting us know if you have any further questions:

    http://lithosphere.lithium.com/t5/Developers/Display-user-s-real-name-instead-of-user-handle/m-p/30405/highlight/true#M289

    • Inactive User's avatar
      Inactive User

      I think I understand what you're saying but here's my problem... I want to edit the 'Location' text portion (in the picture) of the blog message. Now, correct me if I'm wrong, but there isn't a way to edit a Lithium component as far as Freemarker goes. (I know you can edit the text using the Toolbelt, which is what I was hoping to use). Thanks for your help. I appreciate it.

       

      example.png

      • Inactive User's avatar
        Inactive User
        This would be the REST call: rest("/users/id/${env.context.message.author.id?c}/profiles/name/userlocation").value