We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28514
    • 25 Posts
    I have a list of links in a text area which I want to show up in a menu. The menu needs to show the 5 most recent links from the link page. I was thinking about the snippet ’ListIndexer’, but that wil only show recent pages which you created and not text. How can I achieve to show the recent text/links which I added in a content area?

      • 28514
      • 25 Posts
      No one? I want something similiar to the ditto snippet, but instead of documents I want to show links that are in a piece of text
        • 4172
        • 5,888 Posts
        you can try this:

        <?php
        /*
         * call example:
         * <ul>
         * [!text2items? &tpl=`myitemchunk`&source=`mysourceTV`&display=`all`!]
         * </ul>
         * 
         * content example:
         * FIELDNAMES:link||linktext
         * www.link1.com||linktext1
         * www.link2.com||linktext2
         * www.link3.com||linktext3
         * www.link4.com||linktext4
         * 
         * chunk example: 
         * <li><a href="http://[+link+]">[+linktext+]</a></li>
         * 
         * or:
         * <li><a href="http://[+0+]">[+1+]</a></li>
         * (this will work also without the first line in chunk: 'FIELDNAMES:.......')
         * 
         * author: Bruno Perner - [email protected]
         * 
         */
        
        
        
        $display = isset ($display)?$display:'3';
        $sourceTV = isset ($source)?$source:'content';
        $docid = isset ($docid)?$docid:null;
        
        $tv = $modx->getTemplateVarOutput($sourceTV,$docid);
        $text = $tv[$sourceTV];
        
        $text = str_replace('\r', '', $text);
        $text = preg_replace('/(?<!>)\n/', "#break#", $text);
        $items = explode('#break#', $text);
        $output = '';
        if (isset($tpl)){
        if (count($items) > 0)
        {
            $iteration = 0;
        	$fieldnames=array();
        	if (substr($items[0],0,11)=='FIELDNAMES:'){
        		$fieldnames=explode(':',$items[0]);
        		$fieldnames=explode('||',trim($fieldnames[1]));
        		unset($items[0]);
        	}
            foreach ($items as $item)
            {
                if ($display !=='all'&&$iteration == $display) break;
        		$item=explode('||',trim($item));
        		$item['iteration']=$iteration;
        		if (count($fieldnames>0)){
        			foreach ($fieldnames as $key=>$fieldname){
        				$item[$fieldname]=$item[$key];
        			}
        		}
        		
                $output.=$modx->parseChunk($tpl,$item,'[+','+]');
                $iteration++;
        }
        }	
        }
        else{
        	$output= '<pre>'.print_r($items,true).'</pre>';
        }
        
        return $output;
        ?>
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 28514
          • 25 Posts
          In my html I get

          <li><a href="http://"></a></li>

          But not the links that are in my TV. Which settings should I put in my TV?
            • 4172
            • 5,888 Posts
            use textarea-tv with example-content:

            FIELDNAMES:link||linktext
            www.link1.com||linktext1
            www.link2.com||linktext2
            www.link3.com||linktext3
            www.link4.com||linktext4
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 28514
              • 25 Posts
              mmh, doesn’t work.

              Now I get this. But now I don’t have spaces after the `

              Array
              (
              [0] =>

              [!links?&tpl=`link`&source=`mysourceTV`&display=`all`!]

              [1] =>



              [2] =>

              )

                • 4172
                • 5,888 Posts
                ok, had a little bug and have fixed it now. Can test it, if it works now.
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 28514
                  • 25 Posts
                  Lovely, it works fine laugh

                  thank you!