We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51347
    • 82 Posts
    Hello MODx comunity,

    i cant set my placeholder as link in chunk:

    Snippet:
    
    $newsite = "24";
    $modx->setPlaceholder('mysite', $newsite);
    
    $mychunk = $modx->getChunk('site-tpl');
     
    $res = $modx->getObject('modResource',$id);
    $res->set('content',$mychunk);
    $res->save();
    
    


    Chunk site-tpl:
    Here is my new site: <a href="[[~[[+mysite]]]]">My new Site</a><br>
    TestID: [[+mysite]]
    


    HTML:
    Here is my new site: <a href="">My new Site</a><br>
    TestID: 24
    



    what is wrong here?

    This question has been answered by Bruno17. See the first response.

      • 17301
      • 932 Posts
      Try
      <a href="index.php?id=[[+mysite]]">My New Site</a>
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 51347
        • 82 Posts
        That doesn't work, i get this in html:

        <a href="index.php?id=24">My New Site</a>
        • discuss.answer
          • 4172
          • 5,888 Posts
          try this:
          $newsite = "24";
          
          $properties = array();
          $properties['mysite'] = $newsite;
           
          $mychunk = $modx->getChunk('site-tpl',$properties);
            
          $res = $modx->getObject('modResource',$id);
          $res->set('content',$mychunk);
          $res->save();
          
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 51347
            • 82 Posts
            Thank you guys, it work! But this example work only with
            $newsite = "24";


            Now i try to get the id from doc and it doesnt work with $newsite more... Why?

            $doc = $modx->newObject('modDocument');
            $doc->set('parent', $id2);
            $doc->set('pagetitle',$pagetitle7);
            
            $doc->save();
            $newsite = $doc->get('id');
            

              • 4172
              • 5,888 Posts
              what is your whole code now?
              what are you trying at all? Maybe there a better ways to get done, what you want
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 51347
                • 82 Posts
                Here is my snippet. I create 2 pages (parent & child) and give the parent one link to the child.

                /*--------- Work vom Formular abrufen ---------*/
                $work = $_POST["work"]; 
                
                if (isset($work)) {
                
                // Erstellt die Überseite
                      
                    $pagetitle = $work;
                    $parent = "0";
                    $alias = "my-". $work;
                    $template = 3;
                    $richtext = 0;
                    $published = true;
                
                $doc = $modx->newObject('modDocument');
                    $doc->set('parent',$parent);
                    $doc->set('pagetitle',$pagetitle);
                    $doc->set('alias',$alias);
                    $doc->set('template',$template);
                    $doc->set('published',$published);
                    $doc->set('richtext',$richtext);    
                    $doc->save();
                    $id = $doc->get('id');
                
                
                // Erstellt die Unterseite
                
                    $pagetitle3 = "Arbeit 1";
                    $template3 = "3";
                    $alias3 = "meine-arbeiten";
                    $published3 = true;
                    $hidemenu3 = true;
                
                    $doc = $modx->newObject('modDocument');
                    $doc->set('parent', $id);
                    $doc->set('pagetitle',$pagetitle3);
                    $doc->set('alias',$alias3);
                    $doc->set('template',$template3);
                    $doc->set('published',$published3);
                    $doc->set('hidemenu',$hidemenu3);
                    $doc->save(); 
                    $unterseiteid = $doc->get('id');
                
                
                //  Bearbeitet den Content der Startseite und fügt Verlinkungen zu den Unterseiten ein
                 
                    $properties = array();
                    $properties['unterseiteid'] = $unterseiteid;
                    
                    $mychunk = $modx->getChunk('kat-templates',$properties);
                    echo $mychunk;
                
                    $res = $modx->getObject('modResource',$id);
                    $res->set('content',$mychunk);
                    $res->save();
                
                }
                


                My "kat-templates" Chunk:

                <h1>Überseite von Work</h1>
                <a href="[[~[[+unterseiteid]]]]">Hier geht es direkt zu den einzelnen Arbeitsbereichen</a>
                


                Thats it. [ed. note: joe-petts last edited this post 6 years, 7 months ago.]
                  • 4172
                  • 5,888 Posts
                  Why not just a snippet, like getResources or pdoResources to get the children of the parent dynamically?
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 51347
                    • 82 Posts
                    I need one snippet, which i can copy for my other sites without other plugins. I try to create fast and minimized snippet for my individual applications.

                    It's possible to get the id's with my own snippet similare "FastField".

                    [[++site_url]][[!myFF? &tv=`uri` &id=`[[+unterseiteid]]`]]
                    


                    But i hope find smarter way to solve that. [ed. note: joe-petts last edited this post 6 years, 7 months ago.]
                      • 3749
                      • 24,544 Posts
                      If you can use the raw value of the TV and the TV is never empty or set to a default value, something like this will be very fast:


                      $resourceId = 23; //$modx->resource->get('id') ??
                      $tvId = 12;
                       
                      $query = $modx->newQuery('modTemplateVarResource', array(
                          'contentid' => $resourceId,
                          'tmplvarid' => $tvId,
                      ));
                      $query->select('value');
                      $return $modx->getOption('site_url') . $modx->getValue($query->prepare());


                      Note that you would no longer need the site_url tag prefix.
                        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