We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41121
    • 27 Posts
    Hi Folks,

    i need to add about 50 Pages to my Modx Project. And the normal even the fast way of adding Ressources is tiring me out. Ist there a way perhaps to add multi pages at once? Like just giving a list of names? And is there an easy way to set templates for whole sub trees?

    Greets
    Jens
      • 19369
      • 1,098 Posts
      About your second question, see this and also this.
        • 39932
        • 483 Posts
        Fuzzical Logic Reply #3, 14 years ago
        It's possible you could run a PHP script. Are they already uploaded to your site, or do they need to be fetched?
          Website: Extended Dialog Development Blog: on Extended Dialog
          Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
          Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

          Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
          • 3749
          • 24,544 Posts
          Here you go:

          <?php
          $pagetitles = 'pagetitle1,pagetitle2,pagetitle3';
          $resources = explode(',', $pagetitles);
          
          foreach ($resources as $resource) {
              $res = $this->modx->getObject('modResource', array('pagetitle' => $resource));
              if (!$res) {
                  $alias = str_replace(' ', '-', strtolower($resource));
                  $fields = array(
                      'pagetitle' => $resource,
                      'alias' => $alias,
                      'published' => $this->modx->getOption('publish_default', null),
                      'richtext' => $this->modx->getOption('richtext_default', null),
                      'hidemenu' => $this->modx->getOption('hidemenu_default', null),
                      'cacheable' => $this->modx->getOption('cache_default', null),
                      'searchable' => $this->modx->getOption('search_default', null),
                      'context' => $this->modx->getOption('default_context', null),
                      'template' => $this->modx->getOption('default_template', null),
                  );
                  /* @var $res modResource */
                  $res = $this->modx->newObject('modDocument', $fields);
                  if ($res) {
                      $res->setContent("Content goes here");
                      $res->save();
                      $this->modx->log(MODX::LOG_LEVEL_INFO, '    Created resource object ' . $resource);
                  }
                  else {
                      $this->modx->log(MODX::LOG_LEVEL_INFO, '    Could not create resource object ' .
                          $resource);
                  }
              } else {
                  $this->modx->log(MODX::LOG_LEVEL_INFO, '    Resource already exists: ' .
                      $resource);
              }
          }



          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years ago.]
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 41121
            • 27 Posts
            Hey guys,

            thx, i will look into this.

            bye
            Jens