Context in template component

  • 1
  • Question
  • Updated 2 years ago
  • Answered
Hi all,

I have a visualforce page to show a map in the detail page of a country. I have it in the detail page and its working perfectly,

Now I'm doing a list of countries with a table and drawers, the list is based in country regions (Africa, Europe, Asia, North America, South america, Pacific islands,....).

For each region you can open a drawer in the table to see a table of countries and for each country you can open a drawer to see the information of the country.

I have 3 models, Region, Countries of the region and Country Info. This is a simplyfied version of what I have (there are another tables with other country lists inside tabs, the purpose of the Country Info model is not to populate all the country information in all the different country models I have)

When I open the drawer all the conditions are set and the field editors and tables are with the context configured to show only the information of the region opened and the information of the country opened.

All is working correctly but I have a template component in the country to show an iframe of the map of the country linked to the country information model.

That model is queried each time to add the opened drawer data.

The problem is if I open 3 drawers the template shows 3 maps, each map of each country I have opened.

So, my question is: Can I set the context of a template field to prevent this? 
Photo of Pablo Martinez

Pablo Martinez

  • 2,468 Points 2k badge 2x thumb

Posted 4 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
In the drawer "Before Load" actions, did you set the query action to the non default option? I think it's called "Get more Rows" .
Photo of Pablo Martinez

Pablo Martinez

  • 2,468 Points 2k badge 2x thumb
I have setted to add rows to not to loose the other drawers info
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Pablo,  I'm confused.  The expected behavior is that when you open a drawer,  the components inside that drawer operate in the context of the table row.  If the template is bound to the same model as the table this will work without any further definition.   But that does not seem like the behavior you are looking for. 

Do you want all the three maps to show three different countries?  I think this should work.  Or do you want the three maps to show all the countries for drawers that have been opnened. I don't think this will be possible without some substantial custom code. 
Photo of Pablo Martinez

Pablo Martinez

  • 2,468 Points 2k badge 2x thumb
It's what pat comments, you can only set the context to certain components.

The template is linked to the model that has 3 rows but in the drawer is only showing 1 row in the field editor because of the context.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
I think that only components that offer this setting can be set using context. Here's a list of components that do offer this setting.
  • Field Editor
  • Table
  • Page Title
  • Queue
So, that said, you have to come up with a way to set the template on drawer load. Merge Syntax in Templates update as changes are made to the referenced field. I wonder if there's a way to set the values of Template field using javascript. If so, it shouldn't be all that difficult to do.

It would great to be able to use merge syntax with the option to merge once and not update.
Photo of Pablo Martinez

Pablo Martinez

  • 2,468 Points 2k badge 2x thumb
mmm ok, I will investigate the javascript option,

I can create with a template something like <div class="map" id="COUNTRYID" and every time a drawer is open for each .map get the ID and put the map.

But, If I execute this code before open, the div with the map won't exist in that moment, so is going to put the map in all the drawers opened before but not in this one.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
I would try using a Field Editor with a Template within it first. This should work in 5 minutes.
Photo of Pablo Martinez

Pablo Martinez

  • 2,468 Points 2k badge 2x thumb
Good good, you are good
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
You can however use a template field within a Field Editor component. This would have the Id of the row in context.
Photo of Pablo Martinez

Pablo Martinez

  • 2,468 Points 2k badge 2x thumb
It works perfectly.

You are the man. Thanks
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
yw. :D
Photo of mB Andréas K.LeF

mB Andréas K.LeF

  • 1,244 Points 1k badge 2x thumb
Two years later, and yes, using the mB Template you can now have Context in a template component! (At least, in the builder. The functionality was already there, just hidden)

Please visit https://github.com/mBlazonry/mBlazonrySupport  for installation instructions, 
updated instructions, new versions of this and other components!
(Edited)