Print Template Script (Reference another element by id)

I want to create a script that targets multiple elements within a print context, how can I do this.

In jQuery I would use:

$('#myid').attr

In Javascript I would use:

document.getElementById('myid').attr

But neither are supported in designer…

Thanks

Liam

You can do this using a Text Script.

More on using scripts here: PlanetPress Connect 1.6.1 User Guide

Briefly, you’ll want to create a new Text Script. You’ll notice at the top you have the choice of Selector, Text, or Selector and Text. The one you’ll probably want to start with is Selector. Click the radio button and then in the Selector text field above, you will insert your selector. This uses standard CSS syntax, so you can use it to select on an ID, Class, or HTML Tag, or any combination allowed by CSS.

To start writing the script, click Expand at the bottom. This will show you a very basic example of a selector script like you see below, where ‘results’ is the element returned by your selector. You can then begin to manipulate it however you need to.

var field, result = “”;

field = record.fields[“ExtraData”];
if (field !== “”) result += field;

results.html(result);

You may also want to take a look at this how-to that goes into a more advanced example of a selector script.

https://learn.objectiflune.com/en-us/howto/scripts-translate-and-replace

Hi AlbertsN

Thanks for your reply, but I think you miss understood my question, I have no problem accessing the results. (i.e. the selector that you are currently using for the script) but I want to access a different sellector (id or class item) that is outside of the scope of the script.

You can do this to create a new selector inside of an existing script:

query('#myid').attr()

Hope this helps!
~Evie

perfect, thanks Evie.