4 Replies Latest reply on Mar 18, 2016 5:13 AM by iphitos

    Best practice? Master pages & override question


      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

        • 1. Re: Best practice? Master pages & override question
          Marc Autret Level 4

          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.




          • 2. Re: Best practice? Master pages & override question
            iphitos Level 1

            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[i];

                  !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



            • 3. Re: Best practice? Master pages & override question
              Vamitul Level 4

              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

              • 4. Re: Best practice? Master pages & override question
                iphitos Level 1

                I am not doing anything with myItem except calling override function.


                All other stuff that is done afterwards gets the items from the newly added page using allPageItems.


                As said before, so far the error has not occured again - I will find out when I get back to auto-creating first pages of the mag again. While developing I do only create the current parts instead of the complete mag every time