XF 2.3 Changing the var for a <xf:set> tag via JS

Taylor J

Well-known member
If I am sending the following collections to a template $visibleBlogPosts, $draftBlogPosts, $scheduledBlogPosts, $deletedBlogPosts and have a xf set tag as so
<xf:set var="$blogPosts" value={$visibleBlogPosts} />

Is there a way using javascript to change the value $blogPosts to a different one since they have already been passed to the template?
 
Not exactly, since templates are evaluated on the server and JS on the client. It depends what you're looking to accomplish, but you can use a JS handler to update some content on a page via an AJAX request without too much trouble. Consider how the news feed pagination appends content for example, you can use the same handler (XF.InserterClick) but replace the content instead of appending it.
 
I was more so attempting a feable way at making just one of my views more of a SPA to help keep a controller from having 4 different actions that all did the same thing just different blog posts being returned based off of filter conditions.

Before you're reply I ended up going down the route of using a url parameter to be able to just have one action method as I wasn't able to find the <xf:set /> tag (which makes sense as it gets removed from the view as it's used for variable setting) but not sure if that is the cleanest way of handling things either.
 
XF is rendered server-side so there's no built-in way to do rendering on the client if that's what you mean. You can abstract the four actions into a single method (eg. just have the actions call the method with a different argument/finder/etc.), and/or use macros in the template system, if you want to minimize code duplication.
 
Back
Top Bottom