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

    I am looking for the best solution of letting the customer have a small box called Links. Each link is editable

    Eg:

    Links (header)
    Mylink1
    Mylink2
    Mylink3
    Mylink4
    Mylink5
    Mylink6

    One solution is to create 12 TVs, 6 for the Text and 6 for the Urls. There might be an extra one for the header.
    I don’t think this solution is elegant so I am looking for a new one.


    Thank You



      • 4749
      • 623 Posts
      Right now I’m doing this with a custom snippet. I created a TV (textarea) where the client can manually edit the links. The only requirement is that the links be separated by a hard return. Here’s the snippet, call it [!ListBuilder!]
      <?php
      /**
       * Convert a text with linebreaks to a html list
       * written by Roman
       */
      $chunk = isset($chunk) ? $chunk : false;
      $tv = isset($tv) ? $tv : false;
      $delimiter = isset($delimiter) ? $delimiter : "\n";
      $docid = isset($docid) ? $docid : $modx->documentObject['id'];
      
      if($tv){
      	$tvArray = $modx->getTemplateVarOutput(array($tv), $docid);
      	if(!$tvArray[$tv])
      		return;
      	
      	$text = $tvArray[$tv];
      } else if($chunk){
      	$text = $modx->getChunk($chunk);
      	if(!$text)
      		return;
      } else {
      	return;
      }
      
      $lines = explode($delimiter, $text);
      $out = '<ul>';
      foreach($lines as $line){
      	$out .= '<li>' . trim($line) . '</li>';
      }
      $out .= '</ul>';
      return $out;
      ?>
      


      This snippet calls on the text area tv where the links are built manually and separated by line breaks.
      <a href="/sample.html#sample1">Sample 1</a>
      <a href="/sample.html#sample2">Sample 2</a>
      <a href="/sample.html#sample3">Sample 3</a>
      


      I think this could work for you.
        The MODx has you...
        Utah Web Design
        • 5340
        • 1,624 Posts
        not sure I like it sad,

        In my case the URLs are external and quite long.
        For the moment I will hard code the links in a chunk and if there is a need to change them frequently I will use your solution.


        Thank You



          • 7231
          • 4,205 Posts
          I create a container of weblink documents and use Ditto to output the list. To add new ones simply add a new weblink document.
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 5340
            • 1,624 Posts
            How about a related links box? Would you do it statically or is there a snippet who does it automatically


            Thx
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              You still have to input the links somewhere. There’s any number of ways you can display the links, once you decide where you’re going to put them.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org