0

I've been trying to insert/reference an SSJS code resource in my landing page but using the CloudPagesURL(123) function doesn't seem to work? I've been using the function when referencing javascript using the format below and is working fine:

<script src="%%=CloudPagesURL(001)=%%"></script>

Using the above format doesn't work for my page, neither the ones below:

<script  type="javascript" runat="server" src="%%=CloudPagesURL(123)=%%"></script>
<script  type="javascript" runat="server">%%=CloudPagesURL(123)=%%</script>

or directly pasting the function in the HTML - %%=CloudPagesURL(123)=%%

Does SSJS needs to be pasted directly in the HTML? Thanks in advance.

1 Answer 1

2

As @LukasLunow stated, this is not possible in the same way it is in Client-side JS. You can 'fake' it in a couple ways, but that comes with its own caveats. For instance, if you are planning on building an actual 'Library' like you would for JS, this is not likely to be your solution as it will be a synchronous load that will delay your page load and eat up unnecessary processing. This answer gives good detail on how to do it via a Content Block - which would be the preferred resource anyway as it removes the extra steps of utilizing HTTP methods and will not cost any super messages.

Something like:

<script runat="server">
Platform.Load("Core","1.1.1");
var blockID = 12345;
eval('<script runat=server>' + Platform.Function.ContentBlockByID(blockID) + '<' + '/script>');

var debug = 1;
debugWrite('This','Flipping Worked');
</script>

Where the content block looks like:

<script runat=server>
  function debugWrite(key,value,override) {
    //if override = 1 then do not write anything
    override ?  '': debug ? Write('<br><b>' + key + '</b>: ' + value) : '' ;
}
</script>

Which outputs:

This: Flipping Worked

1
  • 2
    Thank you! I now just use Content Blocks.
    – ClinttErno
    Commented Jul 6, 2020 at 10:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .