Question

Photo of Trey Hendon III

0

Merge Field Context

I thought I had a cool idea, but it turns out the context of the Merge Fields is tied to the creator of the block, not the context of who's information I might be viewing.

I'm trying to add a link to my Group Members Details that would take me to the Person's Page.  I tried adding the following in a block on the Group Member Detail Page (140):

<div class="text-right"><a href="/Person/{{ Person.Id }}" target="_blank" class="btn btn-primary">View {{ Person.NickName }}'s Record</a></div>

Unfortunately, it is tied to my Id and NickName no matter which person's details I view.  Has anyone figured out a way to get the context of the currenly viewed person's info exposed to the HTML editor?  Is this possibly a bug in the scope of the Merge Fields?

  • Photo of David Turner

    1

    We also recently updated the HTML Content Detail block to be "context aware" so after next update (0.10), you will be able to do what you were trying to do.  After 0.10 is released, here's the steps you'd take to accomplish this...

    1. Add HTML Content block to the Group Member page (I added it to the feature zone)
    2. Edit block properties of HTML Content block.  At bottom of Basic Settings there will be a new "Context" section with an "Entity Type" property.  Set it to "Group Member".  Also make sure Cache Duration is set to 0.
    3. Edit the HTML content to be something similiar to...
      {% if ContextEntity %}<span class='pull-right'><a href='~/Person/{{ ContextEntity.PersonId }}'>Person Profile</a></span>{% endif %}
    4. Edit the Page properties on page and under "Advanced Settings" tab and "Context Parameters" section, set the "Group Member Parameter Name" to "GroupMemberId".
    5. Refresh page and link should appear.

    -David

    • Trey Hendon III

      Got this going after .10 upgrade and works great, thanks! Quick question, is there a way to find a list of what merge options are returned for the ContextEntity since it's not in the picker?

    • Trey Hendon III

      Turns out I was wrong, or misunderstand (very likely the case) the Context feature. Using the steps above, I found that the link only worked on the Group Member's page which I created the link on. So rather than always getting the Context of the GroupMemberId and giving me the current person's PersonId, somehow it also got tied to only displaying that link on the one record I was on when I created it. Does that make sense? Is that correct functionality?

    • David Turner

      Sounds like it might be caching. Did you set the cache duration to 0?. Currently, since context can be so dynamic, it's difficult to show available merge fields, but will take a look at trying to get them to appear in picker. If you know the object type, you could take a look at the model source (https://github.com/SparkDevNetwork/Rock/tree/develop/Rock/Model) and follow the properties there. What exactly are you trying to display? Also, FYI, the merge fields for context objects will change slightly in the next update 0.11 to support using merge fields for multiple context objects (instead of "ContextEntity.[Field] " you'll have to change it to use "Context.GroupMember.[Field]" ).

    • Trey Hendon III

      Good to know that will be changing, I'll keep an eye on it.


      I did check the cache because that was my first thought. I was trying to display that link from a Group Member Detail page to the corresponding Person Details page. But, what happens is it only displays the link when I view the one Group Member's Details page that I was viewing when I inserted the above code.


      Scenario: I was on Person A's Group Member Details page and followed the steps above. Then, when I viewed Person B's Group Member Details, the block doesn't display anything and if I edit the block while on Person B, the block Edit HTML is blank. However, as soon as I go back to Person A, the link appears as it was and the block's Edit HTML has all the code above still there.


      Rather than being a merge field for each GroupMemberId when the page is viewed it's like it's creating a new instance of the block tied to the GroupMemberId. Does that makes sense? Is that what it's supposed to do? (I could see this behavior as a cool feature too.)

    • David Turner

      Can you confirm that the "Context Parameter" and "Context Name" values for your HTML block are blank. The "Entity Type" under the Context section should be set to 'Group Member'. I suppose it might be a bit confusing that we have different 'context' settings. The Entity Type setting under the Context section is a way for the block to tell the page, "hey, I care about this type of object, load it into memory for me to use". The "Context Parameter" setting tells the block that whatever content you enter is specific to each value of that parameter. So if you set it to "GroupMemberId", then any content you enter when the query string has groupmemberid=1 will be different than when the page has a query string of groupmember=2.

    • David Turner

      Here's a sample content you could use as well...
      <a href='~/person/{{ ContextEntity.Person.Id }}'>{{ ContextEntity.Person.FullName }} Profile</a>

    • Trey Hendon III

      Brilliant! The Context Parameter and Context Name must have been it (I had deleted the block so I just recreated leaving them blank). I do remember populating them following the CMS Guide for using context. Great to know that BOTH types of context are available!

  • Photo of Jim Michael

    0

    Trey, does the block you're dealing with have a definable Context setting? If so, it might just be a matter of setting the context to the right "object." There's a section in the web sites guide that talks about this http://www.rockrms.com/Rock/BookContent/14/14#usingcontext

    • Trey Hendon III

      Yeah, I added the "Context Parameter" setting of "GroupMemberId" since the URL on the page is: /page/140?GroupMemberId=27
      I've also made sure the Cache Duration is set to "0".

    • Trey Hendon III

      For now, I found that I can use jQuery and access some hidden inputs ending in hfPersonId and hfPersonName to do what I need.