Populate a template with value from a button - doable with L&L?

Hi,
I have a question regarding the feasibility of something with L&L. I have a template that fetches different data for every user with

<Loop type=course_recap>
<If field=etudiant_suivi includes value="{User id}">

As an admin, I’d sometime like to select a user and see what said user would see. I’d like to be able to see that without having to load a different page, for example, by clicking on a dropdown list and having the output displayed just below.
Would there be a way to achieve this with L&L? Should I look for scripts to achieve this?
I’m not looking for a practical answer with code, just asking for directions on what to look for :roll_eyes:

Thanks in advance!

Adrien

The easiest way to achieve this would probably just be with some kind of switch-to-user plugin. Although this wouldn’t work if you needed that page to be filterable exclusively from the front end.

The cleanest way to achieve this would probably be with some kind of facet/filter that allows you to select a user and then modifies the query of the page based on that. There are a few examples on this forum of people using FacetWP for this, but it requires digging into a bit of PHP.

I’d think that the two most L&L-centric ways of achieving this would either be with a form plugin or a URL query. The URL query would probably be a bit messy since you couldn’t create a convenient dynamic control in the current version of L&L. I’m imagining you could dynamically generate a list of users with links to the current page with a URL query added and then you could filter the loop on your page based on whether that URL query existed on the current page. The syntax for getting information about a URL query can be found here. Alternatively, you could try to find a form plugin that allows you to get a value from a particular form entry. There are performance tradeoffs to this approach since you may need a separate plugin, but a quick search seems to indicate that Formidable Forms offers this kind of functionality. So you’d have a dropdown selection option in your form allowing you to select a user and then you could use the shortcode to refer to the value selected by the user in the L&L template. Honestly, neither of those options sound quite perfect, but they’re potential avenues to look into.

Once Tangible Blocks has form fields that can be displayed on the front end of the site, then all of this will be way easier, but for the moment these options are what are coming to me. There are probably other approaches I haven’t thought of.

Unrelated to your question, it looks like you’re currently using an If tag to filter the results of your loop. This is the most flexible approach, but it’s also the worst on performance because you’re looping through every post and then running conditional logic on each item to find out if you should display data about the current item. You might want to read through the part of the Loop tag documentation about filtering the loop to understand the different approaches you might want to take in your template.

Hi Benjamin,

Thank you for your thorough answer. As I feared, it looks like there is no easy way for now, although, I’ll be looking forward to experimenting with Tangible Block and its Form Field when it’s ready.
Also, thanks for pointing me out toward the loop filtering! Although it wasn’t relevant for this specific case, I’ve readjusted several L&L Template by filtering when possible.

1 Like