Target=_Blank for Cards report template

cardsreport.PNGI wanted to use the “Cards” report template for a small report which lists file attachments. When the user clicks on one of the cards, the file should download and open in a new tab/window. Unfortunately, the Cards report template does not include a placeholder for extra attributes for the anchor tag, so it won’t let me add “target=_blank” like I would normally.

One solution is to edit the Cards template to add the extra placeholder; however, this means breaking the subscription from the universal theme.

As a workaround for this I’ve added a small bit of javascript to add the attribute after page load, and whenever the region is refreshed.

  • Set report static ID, e.g. “mycardsreport”
  • Add Dynamic Action:
    • Event = After Refresh
    • Selection Type = Region
    • Region = (the region)
  • Add True Action: Execute JavaScript Code
    • Code = $("#mycardsreport a.t-Card-wrap").attr("target","_blank"); (replace the report static ID in the selector)
    • Fire On Page Load = Yes

Note: this code affects all cards in the chosen report.

5 thoughts on “Target=_Blank for Cards report template

    1. Good point to note Scott. In my case, it seems to work fine with Static, even when the region is refreshed by the dropzone plugin I’m using on the page. I’m not sure if there’s something special about that that means I don’t need to worry about dynamic scope in this case.

      Like

    1. Hi Tony,

      I often edit the templates in my projects, but since the Universal Theme came I’ve tried to avoid changing it so that it can get bugfixes and upgrades when Apex is patched. That said, I’m not above making some modifications to the theme if needed.

      In this case, however, I’ve used a very simple DA to get around the limitation – partly just to see how it goes. I’m not sure that using DAs to modify the DOM like this is generally a great approach either. If the solution was any more complex I think I’d veto it.

      The fact is, making modifications in this way generally runs the risk of being made redundant or even broken if/when the template changes anyway; and if the target of the modification is not constrained correctly (e.g. in my case, I’m limiting the change to a single region, and only targeting a certain class) there might be unexpected results if/when the page is changed later on.

      Like

  1. I faced the problem with different cards where just some had to be opened in a new tab. Another one was targeting a modal page e.g.

    For that I used the CARD_MODIFIERS tag to add a custom class (e.g. “add_blank” , after that just change the Dynamic Action to:

    $(“#your_report_region li.add_blank a.t-Card-wrap”).attr(“target”,”_blank”);

    So you keep the subscription and have conditional _blank card links :)

    Like

Comments are closed.