Skip to main content
March 9, 2016
Question

Best practice? Master pages & override question

  • March 9, 2016
  • 1 reply
  • 568 views

Hi all,

I am currently developing a more or less complex script to create a magazine from scratch with contents from a database (by using porky) and would like to ask the gurus here for a best practice tip about how to use master layouts.

The magazine has several master pages for the different contents where I have set placeholder textboxes that (later in the process) will be getting filled with the contents from the database.

Some of the masters will only be used on one page (e.g.: cover, imprint, authors) in the whole mag, some others will be used for several pages (e.g.: articles, news).

So far I have been doing this by:

- add a new page and set is as the active one

- apply the correct master for this specific page

- using override to be able to alter the pageItems that come along from the master


This works so far but I assume I am doing something wrong because when replacing the placeholders contents with the contents from the database, this will also alter the pageItems/placeholders on the master itself instead of only the ones on the active page. So when adding another page that uses the same master, the placeholders from the master will already have the content of the last page instead of being empty.

What would the best practice/correct way be that will only alter the pageItems on the page and leave the master as is, so I can reuse it?

Thank you in advance for any help

This topic has been closed for replies.

1 reply

Marc Autret
Legend
March 10, 2016

Hi iphitos,

Your storyline sounds correct (except you don't need to make the added page 'active') but maybe you don't use the override() method properly.

Let myPage be the new page having myMasterSpread applied, that is, myPage.appliedMaster = myMasterSpread.

Now let's consider the master item myMasterItem that you want to override on myPage, for example myMasterItem = myMasterSpread.textFrames[0].

The working command should look like this:

var myPageItem = myMasterItem.override(myPage);

and then you can operate on myPageItem—which is distinct from myMasterItem.

Hope that helps.

@+

Marc

March 10, 2016

Hi Marc,

thank you for responding so quickly.

This is basically what I am doing... after the new page has been added, I use this to override all the items that come from the master:

myPage.appliedMaster = myDoc.masterSpreads.item(myMaster);

if (myPage.appliedMaster !== null) {

  for (var i = myPage.appliedMaster.pageItems.length; i > 0; i--) {

    try {

      var myItem = myPage.appliedMaster.pageItems;

      !myItem.locked ? myItem.override(myPage) : 0;

    } catch(e) {} 

  }

}

So this seems to be right...

(btw: is there a [code][/code] tag for postings here?)

And even more strange - the problem seems to not be existent any more... at least not with that part of the script that I have just tested.

Either I must have made a change somewhere else (after posting yesterday) that fixed the problem or the problem might be isolated to specific contents/scripts. I will re-check whether it still happens and report

Thanks again

Michael

Vamitul
Legend
March 11, 2016

No, you are not!!

!myItem.locked ? myItem.override(myPage) : 0;

myItems is still the one on the masterpage

should be something like:

var myNewItem= !myItem.locked ? myItem.override(myPage) : 0;

// do stuff to myNewItem