POST Code Injection - Question


Is it possible to use the Code Injection part of a post to add some custom data, IE a resource key.

Then in the post theme, reference the resource key thats in the post code injection part?

Resource key (in code injection) + theme template/ahref = the full link required for a button.

I think it’s possible, i just need to be pointed in the right direction on how to pull this off code wise.

Pretty sure i’ll need todo some custom varibles?

Im wanting todo a IF Member, show some code in the theme, and link in the resource key.

Thanks in advance

Is there a reason you can’t just use code injection to generate that link and apply it?

<a id="resource" href="#">Link</a>

document.getElementById('resource').href = '';
1 Like

Thanks for the reply! I think that is exactly what im after!

How would i get that URL ( into the href="#"> or will the # automatically do it?

The href="#" is just a placeholder, and translate to “when you click this link, scroll to the top of the page”.

The document.getElementById('resource').href = ... portion translates to "give me the element that has an id of resource, and set the href property to ..., and that’s the mechanism which updates the url

1 Like

That works perfectly! One more question.


{{#if @member.paid}}
  <a id="resourcekey" class="c-btn c-btn--loading c-btn--full href="#">Download Now</a>

Code Injection diffrent each per post:

        document.getElementById('resourcekey').href = 'dece3584ef';

What im trying todo is put the first part of the URL (clickable button) behind a paywall to a download link.

The first part of the URL is always the same,

But if we add the resourcekey of “dece3584ef” to the url it’ll turn into a working link

How would i make this work?

You can just make dece3584ef that full URL


        document.getElementById('resourcekey').href = '';

However, to add a bit more security, another option is to keep the main part of the URL hidden in the link:

<!-- handlebars -->
<noscript><style>#resourcekey{display:none}</style><noscript> <!-- hide the link for browsers that disable js-->
{{#if @member.paid}}
  <a id="resourcekey" class="c-btn c-btn--loading c-btn--full href="">Download Now</a>

<!--- code injection -->
const el = document.getElementById('resourcekey');
if (el) {
  el.href = el.href + '{key}';